package com.example.mypen;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.Menu;
import android.view.*;
import android.view.MotionEvent;
public class MainActivity extends Activity{
private Paint paint = new Paint();
private Path path = new Path();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
paint.setAntiAlias(true);
paint.setStrokeWidth(6f);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
}
public void onDraw(Canvas canvas){
canvas.drawPath(path,paint);
}
public boolean onTouchEvent(MotionEvent me){
float eventX=me.getX();
float eventY=me.getY();
switch (me.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
}
答案 0 :(得分:1)
尝试在onTouchEvent方法
中使视图无效