0

ビットマップの位置を取得する方法とOnTouchEventを以下のように定義する方法を他の質問で読みましたが、ビットマップオブジェクトではリスナーを設定できません。どうすればよいですか?

public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX()  // or getRawX();
int y = event.getY();

switch(action){
case MotionEvent.ACTION_DOWN:
    if (x >= xOfYourBitmap && x < (xOfYourBitmap + yourBitmap.getWidth())
            && y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight())) {
        //tada, if this is true, you've started your click inside your bitmap
    }
    break;
}
}
4

1 に答える 1

0

内にビットマップを描画する必要がありますView(たとえば、プレーンで背景として、または のソース/イメージとしてView描画します)。次に、これに を付けて、そのリスナーで処理を行うことができます。BitmapImageViewonTouchListenerViewonTouchEvent

于 2013-02-27T21:17:53.250 に答える