SwipRefreshLayout 和ViewPager及CoordinatorLayout 解决滑动冲突

SwipRefreshLayout 和ViewPager和CoordinatorLayout 解决滑动冲突

1 CoordinatorLayout和SwipRefreshLayout 冲突解决:

mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//verticalOffset  AppBarLayout 滑动的距离,当滑动到最低端时为0
// 往上滑为负,所以>=0 时为最低端,<0 时为 向上滑动了一段距离
        if (verticalOffset >= 0) {
            mRefreshLayout.setEnabled(true);
        } else {
            mRefreshLayout.setEnabled(false);
        }
});

2 SwipRefreshLayout 和ViewPager的滑动冲突解决:

onPageScrollStateChanged() 参数:

  • @param state The new scroll state.
  • @see ViewPager#SCROLL_STATE_IDLE 空闲
  • @see ViewPager#SCROLL_STATE_DRAGGING 滑动
  • @see ViewPager#SCROLL_STATE_SETTLING 停止滑动

/**

  • Indicates that the pager is in an idle, settled state. The current page
  • is fully in view and no animation is in progress.
    */
    public static final int SCROLL_STATE_IDLE = 0;

/**

  • Indicates that the pager is currently being dragged by the user.
    */
    public static final int SCROLL_STATE_DRAGGING = 1;

/**

  • Indicates that the pager is in the process of settling to a final position.
    */
    public static final int SCROLL_STATE_SETTLING = 2;
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int i, float v, int i1) {
    }

    @Override
    public void onPageSelected(int i) {
    }

    @Override
    public void onPageScrollStateChanged(int i) {
        if(i == 1) {//滑动过程中关闭下拉刷新
            mRefreshLayout.setEnabled(false);//设置不可触发
        }else if(i == 2){//停止滑动时触发,可以刷新
            mRefreshLayout.setEnabled(true);//设置可触发
        }
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值