私は学習目的で単純な Android ペイント プログラムを作成しましたが、ontouch ストロークが描画されないため、次のように試しました: main.java
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;
}
}