Android ontouch事件
public boolean onTouch(View v, MotionEvent event){
。。。。
return true;// 一定要返回true,不然获取不到完整的事件
}
touch事件有多个状态:
ACTION_MOVE //表示为移动手势
ACTION_UP //表示为离开屏幕
ACTION_CANCEL //表示取消手势,不会由用户产生,而是由程序产生的
通过int eventName = event.getAction();获取事件状态,并执行不同的操作:
if(eventName== MotionEvent.ACTION_DOWN){
imageView2.startAnimation(translateAnimation);
}
if(eventName == MotionEvent.ACTION_UP){
imageView2.clearAnimation();
}