SwipeRefreshLayout对纵向的滑动事件很敏感,导致和内部嵌套横向滑动的控件两者冲突,解决方法自定义一个View继承SwipeRefreshLayout,可以参考:
public class VerticalSwipeRefreshLayout extends SwipeRefreshLayout {
private int mTouchSlop;
// 上一次触摸时的X坐标
private float mPrevX;
public VerticalSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// 触发移动事件的最短距离,如果小于这个距离就不触发移动控件
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mPrevX = event.getX();
break;
case MotionEvent.ACTION_MOVE:
final float eventX = event.getX();
float xDiff = Math.abs(eventX - mPrevX);
// Log.d("refresh" ,"move----" + eventX + " " + mPrevX + " " + mTouchSlop);
// 增加60的容差,让下拉刷新在竖直滑动时就可以触发
if (xDiff > mTouchSlop + 60) {
return false;
}
}
return super.onInterceptTouchEvent(event);
}
}
网友评论