最近遇到一个淡疼的bug,banner与下拉刷新的ptr横向滑动冲突,
//左右滑动时刷新控件禁止掉
ptr.disableWhenHorizontalMove(true);
这样写有时候不好使,然后再加上重写ptr
public class PtrClassicRefreshLayout extends PtrClassicFrameLayout {
private boolean disallowInterceptTouchEvent = false;
public PtrClassicRefreshLayout(Context context) {
super(context);
}
public PtrClassicRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PtrClassicRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
disallowInterceptTouchEvent = disallowIntercept;
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_UP:
//解除刷新的屏蔽
this.requestDisallowInterceptTouchEvent(false);
break;
}
if (disallowInterceptTouchEvent) {
//事件向下分发给子控件,子控件会屏蔽掉父控件的刷新
return dispatchTouchEventSupper(e);
}
return super.dispatchTouchEvent(e);
}
}
本文介绍了解决Banner与下拉刷新控件 Ptr 在横向滑动时产生的冲突问题。通过禁用 Ptr 的横向滑动功能,并重写 PtrClassicRefreshLayout 类来确保事件正确分发给子控件,从而避免了滑动冲突。
461

被折叠的 条评论
为什么被折叠?



