在我创建的一个继承自
但是实际上,我得到的结果是这样的:
以下是我的代码:
Button
的类中,我重写了onDraw
函数,在按钮右侧创建了一个指向中心的三角形:![Desired result](https://istack.dev59.com/K8m4m.webp)
![Actual result](https://istack.dev59.com/pN8B3.webp)
Paint paint = new Paint();
@Override
public void onDraw(Canvas canvas)
{
Paint paint = new Paint();
paint.setColor(android.graphics.Color.BLACK);
canvas.drawPaint(paint);
paint.setStrokeWidth(4);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
Point center = new Point(getWidth()/2, getHeight()/2);
Point a=new Point(getWidth(), 0);;
Point b=new Point(getWidth(), getHeight());;
paint.setColor(Color.RED);
Path path= new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.lineTo(b.x, b.y);
path.lineTo(center.x, center.y);
path.lineTo(a.x, a.y);
path.close();
canvas.drawPath(path, paint);
}