开发者

Android - drawing a line

开发者 https://www.devze.com 2023-03-13 05:37 出处:网络
I want to draw a line on the screen usign touch listener, but when I try开发者_如何学C to draw line again, it erases the previous line. I am using the code below.

I want to draw a line on the screen usign touch listener, but when I try开发者_如何学C 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();
     }
}


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();
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号