经过验证,点击一下,会先后执行触摸事件,down-up->点击事件
如果长按后松开,则会先后执行触摸事件,down-长时间触摸事件-up->点击事件
public class MainActivity extends Activity{
private ImageView iv;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView)findViewById(R.id.iv_onclic);
init();
}
private void init(){
iv.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
System.out.println("点击事件");
}
});
iv.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent mEvent) {
// TODO Auto-generated method stub
switch (mEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
System.out.println("触摸down");
break;
case MotionEvent.ACTION_UP:
System.out.println("触摸up");
break;
case MotionEvent.ACTION_MOVE:
System.out.println("触摸move");
break;
default:
break;
}
System.out.println("触摸结束");
return false;//会响应点击事件
//return true;//不会响应点击事件
}
});
iv.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
System.out.println("长时间-----");
return false;
}
});
}
}