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