游戏中的View开发
public class MyView extends View {
private int textX = 20,textY = 20;
public MyView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
//创建一个画笔实例
Paint paint = new Paint();
paint.setColor(Color.RED);
//绘制文本
canvas.drawText("Game", textX, textY, paint);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//获取用户触屏的X轴赋值给文本的X坐标
textX = (int)event.getX();
//获取用户触屏的Y轴赋值给文本的Y坐标
textY = (int)event.getY();
invalidate();
return true;
}
}