public class MyPaintView extends View {
private List allPoints=new ArrayList();
//接受context以及属性集合(宽度,高度等)
public MyPaintView(Context context, AttributeSet attrs) {
super(context, attrs);
super.setOnTouchListener(new OnTouchListenerImp());
}
private class OnTouchListenerImp implements OnTouchListener{
public boolean onTouch(View v, MotionEvent event) {
Point p=new Point((int)event.getX(),(int)event.getY());
if(event.getAction()==MotionEvent.ACTION_DOWN){
//用户按下,表示重新开始保存点
MyPaintView.this.allPoints=new ArrayList();
MyPaintView.this.allPoints.add(p);
}
else if(event.getAction()==MotionEvent.ACTION_UP){
//用户松开
MyPaintView.this.allPoints.add(p);
MyPaintView.this.postInvalidate();//重绘图像
}
自由划线的好用工具类
关注
打赏