问题:RecyclerView列表显示,我滑动这个列表的item时,会触发item的点击事件
解决:调用RecyclerView的addOnItemTouchListener()监听,根据滑动的距离判断是否相应点击事件
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
public float y1,y2,x2,x1;
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
x1 = e.getX();
y1 = e.getY();
}
if (e.getAction() == MotionEvent.ACTION_UP) {
x2 = e.getX();
y2 = e.getY();
if (Math.abs(x1 - x2) < 6) {
return false;// 距离较小,当作click事件来处理
}
if(Math.abs(x1 - x2) >60){ // 真正的onTouch事件
return true;
}
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});