캔버스를 사용하도록보기를 확장했습니다. onDraw() 메서드에서 기본 드로잉을 그립니다. 사용자가 캔버스에서 터치 할 때 캔버스를 onTouchEvent() 메서드 내부에서 사용 했으므로 거기에 이미지를 그려야합니다. 드로잉을 수행하지 않습니다. 코드는 아래에 나와 있습니다. 문제는 무엇이며 어떻게이캔버스 다른 방법으로 이미지를 그릴 수 없습니다.
public class ScreenView extends View(){
static Canvas canvas;
Bitmap bm;
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
this.canvas = canvas;
bm = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
canvas.draw.......
......
...........
}
public boolean onTouchEvent(final MotionEvent event) {
handleTouches(event.getX(), event.getY());
return false;
}
public void handleTouches(float x, float y) {
xLocTouch = (int) x;
yLocTouched = (int) y;
Paint paint = new Paint();
paint.setColor(Color.BLACK);
canvas.drawBitmap(bm, xLocTouch ,yLocTouched , paint);
}
}
Canvas onDraw 메서드에서만 (관련 : dispatchDraw(), draw()) – pskink