Ste*_*ley 29
你应该使用这样的东西:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个开始,但您需要处理case MotionEvent.ACTION_MOVE
并case MotionEvent.ACTION_UP
确保正确处理用户输入.onTouchEvent
每次用户调用该方法:将手指放下,移动已经在屏幕上的手指或抬起手指.每次事件携带手指所在的X和Y坐标.例如,如果你想检查某人在你的位图内部进行攻击,你应该做一些事情,比如在ACTION_DOWN中设置触摸在位图内部开始的布尔值,然后在ACTION_UP上检查你是否仍在位图内.
归档时间: |
|
查看次数: |
18162 次 |
最近记录: |