TabLayout V23不与ViewPager滚动滚动 [英] TabLayout v23 doesn't scroll with ViewPager scroll

查看:300
本文介绍了TabLayout V23不与ViewPager滚动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着新的设计支持库23.0.0,标签为 TabLayout 你拖的时间不被滚动的 ViewPager asociated。当你完成拖动,点击了(在已经选择了选项卡)的卡只能滚动。在此22.2.1工作正常

With the new design support library 23.0.0, the tabs for TabLayout are not being scrolled at the time you drag the ViewPager asociated. The tabs are only scrolled when you finish the dragging and click up (when the tab is already selected). This was working fine on 22.2.1

我一定要添加更多的东西来得到它的工作22.2.1样?它是一个错误吗?有没有解决办法?

Do I have to add something more to get it work like in 22.2.1? Is it a bug? Is there a workaround?

修改

错误固定的最后一个版本23.0.1

Bug fixed with the last version 23.0.1

推荐答案

下面是一种变通方法,解决它,以克里斯建议巴内斯(设计支持库的主要开发者)。在谷歌问题的网页。提到这里这个问题,解决 rel=\"nofollow\">。

Here is a workaround that solves it, proposed by Chris Banes (The main developer of the design support library). This issue was mentioned on the Google Issues page here, and solved here.

设置时,将这个code中的 ViewPager

Put this code when setting the ViewPager:

    viewPager.clearOnPageChangeListeners();
    viewPager.addOnPageChangeListener(new TabLayoutOnPageChangeListener(tabLayout));

另外补充这个类:

Also add this class:

private static class TabLayoutOnPageChangeListener implements ViewPager.OnPageChangeListener {

    private final WeakReference<TabLayout> mTabLayoutRef;
    private int mPreviousScrollState;
    private int mScrollState;

    public TabLayoutOnPageChangeListener(TabLayout tabLayout) {
        mTabLayoutRef = new WeakReference<>(tabLayout);
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        mPreviousScrollState = mScrollState;
        mScrollState = state;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        final TabLayout tabLayout = mTabLayoutRef.get();
        if (tabLayout != null) {
            final boolean updateText = (mScrollState == ViewPager.SCROLL_STATE_DRAGGING)
                    || (mScrollState == ViewPager.SCROLL_STATE_SETTLING
                    && mPreviousScrollState == ViewPager.SCROLL_STATE_DRAGGING);
            tabLayout.setScrollPosition(position, positionOffset, updateText);
        }
    }

    @Override
    public void onPageSelected(int position) {
        final TabLayout tabLayout = mTabLayoutRef.get();
        if (tabLayout != null) {
            tabLayout.getTabAt(position).select();
        }
    }
}

这篇关于TabLayout V23不与ViewPager滚动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆