これが私のやり方です(私にとってはうまくいきます):
- ボタンのビットマップをキャンバスに描画します。
- Android タッチ API を使用して、タッチ座標がビットマップ dst rec にあるかどうかを検出します。
- 上記が当てはまる場合は、キャンバスに「ポップアップ」したいビットマップを描画します。
これにより、これを行う方法についてより良いアイデアが得られることを願っています。
アップデート:
private class Draw extends View implements OnTouchListener {
Rect button = new Rect(); // Define the dimensions of the button here
boolean buttonClicked;
public Draw(Context context) {
super(context);
}
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (buttonClicked == true) {
canvas.drawBitmap(source, null, button, null);
// Source will be a that of a clicked button bitmap
} else {
canvas.drawBitmap(source, null, button, null);
// Source will be a that of a non clicked button bitmap
}
}
@Override
public boolean onTouch(View view, MotionEvent event) {
if (button.contains(event.getX(), event.getY())) {
buttonClicked = true;
} else {
buttonClicked = false;
}
return true;
}
}
PS: コードが動かなくても心配しないでください。私はまだテストしていません。ビューのレンダリング方法がわからない場合は、SurfaceView に移動してレンダリング スレッドを作成することをお勧めします。チュートリアルは次のとおりです: http://www.edu4java.com/androidgame.html