感谢您花时间看这个问题。我正在尝试一些 android 编程,但我碰壁了;不知道如何解决它。我尝试仅在触摸计数为奇数时为特定实体激活动画。那就是touchCount%2 != 0
。
public boolean onTouch(View v, MotionEvent event){
ArrayList<TextView> textToDance = new ArrayList<TextView>();
textToDance.add((TextView)findViewById(R.id.CAD5));
textToDance.add((TextView)findViewById(R.id.CAD10));
textToDance.add((TextView)findViewById(R.id.CAD20));
textToDance.add((TextView)findViewById(R.id.CAD50));
textToDance.add((TextView)findViewById(R.id.CAD100));
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
for(TextView txtAnimate: textToDance){
if(event.getRawX()<= txtAnimate.getX()+txtAnimate.getMeasuredWidth() && event.getRawX()>=txtAnimate.getX()){
if(event.getRawY()<= txtAnimate.getY()+105+txtAnimate.getMeasuredHeight() && event.getRawY()>=txtAnimate.getY()+105){
helpAnimate(txtAnimate, 0);
}
}
}
break;
case MotionEvent.ACTION_MOVE:
Log.d("MOVE","MOVE");
break;
case MotionEvent.ACTION_UP:
Log.d("UP","UP");
break;
default:
break;
}
return true;
}
我试图实现一个 HashMap 但该地图被重置所有 onTouch 被调用。有什么建议么?