import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class DrawViewextendsView {
public float currentX=40;
public float currentY=50;
Paint p=new Paint();
public DrawView(Contextcontext) {
super(context);
}
public DrawView(Contextcontext, AttributeSet set){
super(context, set);
}
@Override
public voidonDraw(Canvas canvas){
super.onDraw(canvas);
p.setColor(Color.GREEN);
canvas.drawCircle(currentX,currentY,15,p);
}
@Override
public booleanonTouchEvent(MotionEvent event){
currentX = event.getX();
currentY= event.getY();
invalidate();
return true;
}
}
网页版简书好难用。