在我创建的扩展Button
的类中,我覆盖了onDraw
函数,在按钮右侧创建了一个指向中心的三角形:
相反,这就是我得到的:
这就是我写的:
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);
}
答案 0 :(得分:2)
你忘记了它的初始点。
像
这样的东西path.moveTo(point1_draw.x,point1_draw.y);
在您的第一个lineTo()
之前
因为lineTo()
需要"最后一点"开始细分。
void lineTo(float x, float y) // Add a line from the last point to the specified point (x,y).
所以,最后,你的鳕鱼看起来像:
Path path= new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(a.x, a.y); // Move to a
path.lineTo(center.x, center.y); // Segment from a to center
path.lineTo(b.x, b.y); // Segment from center to b
path.close(); // Segment from b to a
canvas.drawPath(path, paint);