Android的触摸起来不工作 [英] Android Touch UP not working
问题描述
即时消息还挺坚持了这个项目的Android即时通讯试图弄清楚这是为什么不工作,但我没有idea.This是顺便的自定义视图,以防万一。
问题是这样的事件ACTION_DOWN是可以正常使用即时得到控制台调试触摸1和触摸2,但ACTION_UP,ACTION_CANCEL或默认:不工作我不能算出这个所以任何帮助将是非常美联社$ pciated p $谢谢
公共无效doTouch(MotionEvent事件)
{
INT行动= event.getAction(); 浮X = event.getX();
浮Y = event.getY(); 开关(动作)
{
案例MotionEvent.ACTION_DOWN:
如果(X 125&放大器;&放大器; Y 125){
对于(AnimatedSprite一:mSprites)
{
如果(a.getID()== 1)
{
a.AdvanceToFrame(0);
感人= TRUE;
的System.out.println(触摸1);
// touch_obj1 = TRUE;
}
}
}
否则如果(X GT;的getWidth() - 125安培;&放大器y与其所连接;的getHeight() - 125)
{
对于(AnimatedSprite一:mSprites)
{
如果(a.getID()== 2)
{
a.AdvanceToFrame(1);
的System.out.println(触摸2);
感人= TRUE;
// touch_obj2 = TRUE;
}
}
}
其他
{
感人= FALSE;
}
打破;
案例MotionEvent.ACTION_CANCEL:
案例MotionEvent.ACTION_UP: 的System.out.println(润色);
感人= FALSE;
打破; 默认:
的System.out.println(不接触);
感人= FALSE;
打破;
}
}
这里是IM调用doTouch功能
公共布尔onTouchEvent(MotionEvent事件)
{
thread.doTouch(事件);
返回super.onTouchEvent(事件);
}
它看起来像你的问题是你要处理的 onTouchEvent
触摸事件的方式。你需要,如果你想处理触摸事件从 onTouchEvent
返回true。所以,如果你得到一个 ACTION_DOWN
和 onTouchEvent
返回false,系统将不会向您发送相关的,直到更多的触摸事件接下来的 ACTION_DOWN
事件。
不知道正是你所用的触摸事件做什么,我不能给你一个解决方案,一定会为你的情况下工作,但如果你想获得比 ACTION_DOWN <之外的任何触摸事件/ code>您将需要从
onTouchEvent
。
im kinda stuck with this project in android im trying to figure out why this is not working but i have no idea.This is By the way a custom view just in case.
The problem is this the event ACTION_DOWN is working perfectly im getting the console debug "Touching 1" and "Touching 2" but ACTION_UP,ACTION_CANCEL or default: are not working i cant figure this out so any help would be really appreciated thank you
public void doTouch(MotionEvent event)
{
int action = event.getAction();
float x = event.getX();
float y = event.getY();
switch(action)
{
case MotionEvent.ACTION_DOWN:
if(x < 125 && y < 125){
for(AnimatedSprite a:mSprites)
{
if(a.getID() == 1)
{
a.AdvanceToFrame(0);
touching = true;
System.out.println("Touching 1");
//touch_obj1 = true;
}
}
}
else if(x > getWidth()-125 && y > getHeight()-125)
{
for(AnimatedSprite a:mSprites)
{
if(a.getID() == 2)
{
a.AdvanceToFrame(1);
System.out.println("Touching 2");
touching = true;
//touch_obj2 = true;
}
}
}
else
{
touching = false;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
System.out.println("Touch UP");
touching = false;
break;
default:
System.out.println("NOT Touching");
touching = false;
break;
}
}
here is where im calling the doTouch function
public boolean onTouchEvent(MotionEvent event)
{
thread.doTouch(event);
return super.onTouchEvent(event);
}
It looks like your problem is the way you are handling touch events in onTouchEvent
. You need to return true from onTouchEvent
if you want to handle touch events. So, if you get an ACTION_DOWN
and return false from onTouchEvent
the system will not send you any more touch events related until the next ACTION_DOWN
event.
Without knowing exactly what you are doing with the touch events, I can't give you a solution that will definitely work for your situation, but if you want to receive any touch events other than ACTION_DOWN
you will need to return true from onTouchEvent
.
这篇关于Android的触摸起来不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!