How to draw a Line in ImageView on Android?

前端 未结 4 1671
無奈伤痛
無奈伤痛 2020-12-05 15:50

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.

4条回答
  •  旧巷少年郎
    2020-12-05 16:54

    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

提交回复
热议问题