IM还挺坚持这一项目在机器人即时通讯试图弄清楚这是为什么不工作,但我没有idea.This是顺便说一句,以防万一自定义视图。
问题是这样的事件ACTION_DOWN工作完全即时得到控制台调试“触摸1”和“2触摸”但ACTION_UP,ACTION_CANCEL或默认:不工作我不能算出这个所以任何帮助将非常感激谢谢
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;
}
}
这里是IM调用doTouch功能
public boolean onTouchEvent(MotionEvent event)
{
thread.doTouch(event);
return super.onTouchEvent(event);
}