ViewPager放了3个fragment,在第三个有recyclerView,因为是最后一个了,向左滑删除,逻辑上也不会出现问题
import ;
import ;
import ;
import ;
public class SwipeRecyclerView extends RecyclerView{
public SwipeRecyclerView(Context context) {
super(context);
}
public SwipeRecyclerView(Context context,AttributeSet attrs) {
super(context, attrs);
}
public SwipeRecyclerView(Context context,AttributeSet attrs, int defStyle) {
super(context,attrs,defStyle);
}
float startX = 0;
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
getParent().requestDisallowInterceptTouchEvent(true);
switch (()) {
case MotionEvent.ACTION_DOWN:
startX = ();
break;
case MotionEvent.ACTION_MOVE:
if(()<startX)getParent().requestDisallowInterceptTouchEvent(true);
else getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return (ev);
}
}
当然,其他View例如ListView也是这样处理