How to draw a Line in ImageView on Android?

user776550 picture user776550 · May 30, 2011 · Viewed 25.3k times · Source

I'd Like to know how to draw a Line on ImageView as user swipe their finger ?

Could any body explain this ? Or perhaps any Link to get start on this.

Answer

George picture George · May 30, 2011

You must have your own ImageView and override onDraw function. Use something like this

public class MyImageView extends ImageView{

    public MyImageView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
        canvas.drawLine(0, 0, 20, 20, p);

    }

}

and in your main class create object MyImageView; and when you touch your display call the update(); function