Android - drawing a line

2019-08-27 03:12发布

I want to draw a line on the screen usign touch listener, but when I try to draw line again, it erases the previous line. I am using the code below.

I am unable to find a solution to the problem. Please help.

public class Drawer extends View
{
     public Drawer(Context context)
     {
         super(context);
     }

     protected void onDraw(Canvas canvas)
     {
         Paint p = new Paint();
         p.setColor(colordraw);
         canvas.drawLine(x1, y1, x2 , y2, p);
         invalidate();
     }
}

1条回答
劫难
2楼-- · 2019-08-27 03:58

u can draw a line using canvas object but u r trying to draw second line using bitmap object try to draw with canvas object

 protected void onDraw(Canvas canvas)

 {
     Paint p = new Paint();
     p.setColor(colordraw);
     p.setColor(Color.BLUE);
     canvas.drawLine(x1, y1, x2 , y2, p);
     canvas.drawLine(x1, y1, x2 , y2, p);
     invalidate();
 }
查看更多
登录 后发表回答