0
我讀過其他問題如何獲取位圖的位置以及如何定義OnTouchEvent,但使用Bitmap對象無法設置偵聽器,我該如何做?如何將偵聽器添加到畫布中的位圖? (Android)
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;
}
}
...但以這種方式我不能使用畫布 – Roran 2013-02-27 21:24:33
我不明白。你想用帆布做什麼?在你的問題中,你只是想知道點擊正確的位置。 – 2013-02-27 21:27:07
我的課使用畫布的onDraw方法,我想添加一個監聽器在它繪製的位圖 – Roran 2013-02-27 21:34:35