开发者

Android - drawing a line

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜