当用户关闭移动在Android中一键检测 [英] Detect when a user moves off of a button in Android
问题描述
是否有可能随时检测用户移动他们的手指离开按钮后,他们已经$ P $它pssing下来?
我已经确定,当用户将关闭垂直按钮onTouchListener会得到一个动作(它给出了一个动作:ACTION_CANCEL),但我一直没能找到一种方法来确定当用户水平移离按钮。
公共布尔onTouch(查看arg0中,MotionEvent ARG1){
开关(arg1.getAction()){
案例MotionEvent.ACTION_CANCEL:
案例MotionEvent.ACTION_UP:
开关(arg0.getId()){
案例R.id.my_button:
button.setBackgroundResource(R.drawable.untouched);
打破;
}
打破;
案例MotionEvent.ACTION_DOWN:
开关(arg0.getId()){
案例R.id.my_button:
button.setBackgroundResource(R.drawable.touched);
打破;
}
打破;
}
返回false;
}
试着去下一个:
arg1.getX();
arg1.getY();
ARG1 - 是从code
在这里,你可以得到MotionEvent坐标。接下来,您将做任何与此坐标
希望,它帮助你。
Is it possible to detect anytime a user moves their finger off of a button after they have been pressing down on it?
I have determined that onTouchListener will get an action when the user moves off of the button vertically (It gives an action: ACTION_CANCEL), but I have not been able to find a way to determine when a user moves off the button horizontally.
public boolean onTouch(View arg0, MotionEvent arg1) {
switch(arg1.getAction()){
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.untouched);
break;
}
break;
case MotionEvent.ACTION_DOWN:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.touched);
break;
}
break;
}
return false;
}
Try go next:
arg1.getX();
arg1.getY();
arg1 - is from your code
Here you can get coordinates of MotionEvent. Next you will do anything with this coordinates
Hope, it help you
这篇关于当用户关闭移动在Android中一键检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!