我将如何设置的ImageButton只有当我的手指触摸它改变 [英] How would I set an ImageButton to change only when my finger is touching it
问题描述
我想创建一个事件来改变什么我的图像按钮的样子,但只有当被按下了。到目前为止,我一直使用的是onTouch听众,但只是改变其永久。我找不到像按钮的onKyeUpListener()类型的东西什么。
有没有这样的事情存在吗?
解决
最后的ImageButton按钮=(的ImageButton)findViewById(R.id.ImageButton01); button.setOnTouchListener(新View.OnTouchListener(){ @覆盖
公共布尔onTouch(视图V,MotionEvent事件){ 如果(event.getAction()==(MotionEvent.ACTION_UP)){
//完成后preSS任何你想要的
}
其他{
//做preSS在任何你想要的
}
返回true;
}
});
从的 http://developer.android.com/guide/topics/ui/ui-events.html :
onTouch()...当用户执行作为一个合格的触摸事件,包括preSS,释放,或在屏幕上的任何动作姿态(该项目的范围内)的动作这就是所谓。
块引用>在换句话说,
onTouch
也呼吁释放事件。看看MotionEvent.getAction()
。I want to create an event to change what my image button looks like, but only when it is being pushed down. So far I have been using an onTouch listener, but that just changes it permanently. I can't find anything like an onKyeUpListener() type of thing for the button.
Does anything like this exist?
SOLVED
final ImageButton button = (ImageButton) findViewById(R.id.ImageButton01); button.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == (MotionEvent.ACTION_UP)){ //Do whatever you want after press } else{ //Do whatever you want during press } return true; } });
解决方案From http://developer.android.com/guide/topics/ui/ui-events.html:
onTouch() ... This is called when the user performs an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item).
In other words,
onTouch
is also called for release events. Look atMotionEvent.getAction()
.这篇关于我将如何设置的ImageButton只有当我的手指触摸它改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!