• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

用较短的拖动使ViewPager对齐

用户头像
it1352
帮助1

问题说明

是否可以通过较短的拖动使支持包ViewPager捕捉到下一页?默认行为似乎是,即使我拖动了将近75%的页面,放开时页面仍会跳回到上一页.我想缩短捕捉阈值,并改为将ViewPager捕捉到下一页.

Is there any way to make the support package ViewPager snap to the next page with a shorter drag? The default behaviour seems to be that even if I drag almost 75% the page still snaps back to the previous page when I let go. I'd like to make the snap threshold shorter and make the ViewPager snap to the next page instead.

请注意,这适用于拖动手势.挥动手势已经需要更短的手势.

Note that this applied to drag gesture. A fling gesture requires much shorter gesture already.

正确答案

#1

您可以临时执行此操作,而不必担心ViewPager的内部结构,只要您想增加目标区域即可:

You can do this ad-hoc, without worrying too much about the internals of ViewPager as long as you want to increase the target zone:

private class MyPageChangeListener implements OnPageChangeListener {
    private float mLastPositionOffset = 0f;
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        if(positionOffset < mLastPositionOffset && positionOffset < 0.9) {
            mViewPager.setCurrentItem(position);
        } else if(positionOffset > mLastPositionOffset && positionOffset > 0.1) {
            mViewPager.setCurrentItem(position 1);
        }
        mLastPositionOffset = positionOffset;
    }
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcckjjj
系列文章
更多 icon
同类精品
更多 icon
继续加载