1初始化手势识别变量
private GestureDetector gd = null;
gd = new GestureDetector(mContext, new GestureListener());
2接管触摸事件
convertView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
view = v;
if (event.getAction() == MotionEvent.ACTION_DOWN) {//设置触摸颜色变化
v.setBackgroundResource(R.color.dongao_orange);
}else{
v.setBackgroundResource(0);
}
return gd.onTouchEvent(event);
}
});
3注册手势监听器
private final class GestureListener implements OnGestureListener {
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
Log.d("GestureListener", "onShowPress");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {//单击事件
// TODO Auto-generated method stub
Log.d("GestureListener", "onSingleTapUp");
// view.setBackgroundResource(0);
playVideo(view.getId());
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {//滑动事件
// TODO Auto-generated method stub
Log.d("GestureListener", "onScroll");
//if (e2.getX() - e1.getX() > 1) {//向右滑动
removeListItem(((ViewHolder)view.getTag()).btnDelete,view.getId(),false);
//}
// view.setBackgroundResource(R.color.dongao_orange);
return true;
}
@Override
public void onLongPress(MotionEvent e) {//长按事件 用户体验性不好 不容易发现
// TODO Auto-generated method stub
Log.d("GestureListener", "onLongPress");
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
Log.d("GestureListener", "onFling"+(e2.getX() - e1.getX()));
// if (e2.getX() - e1.getX() > 1) {
// removeListItem(((ViewHolder)view.getTag()).btnDelete,view.getId(),false);
// }
// view.setBackgroundResource(0);
return true;
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
Log.d("GestureListener", "onDown");
// view.setBackgroundResource(R.color.dongao_orange);
return true;
}
}