hackware1993 / MagicIndicator

A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip —— 强大、可定制、易扩展的 ViewPager 指示器框架。是ViewPagerIndicator、TabLayout、PagerSlidingTabStrip的最佳替代品。支持角标,更支持在非ViewPager场景下使用(使用hide()、show()切换Fragment或使用setVisibility切换FrameLayout里的View等),http://www.jianshu.com/p/f3022211821c
9.68k stars 1.54k forks source link

在小米的安卓11手机上,会导致应用整体卡顿 #269

Open chenglin198751 opened 2 years ago

chenglin198751 commented 2 years ago

用户反馈应用卡顿,经过我的跟踪调试,发现在安卓11上,每个页面都卡顿。分析代码,发现,是CommonNavigator类的onLayout()方法被无限次调用,导致UI线程被占用从而整个app都卡顿,在小米的安卓11必现。别的手机的安卓11不知道是不是会出现。 我的修改办法,在CommonNavigator类中: `` private boolean isLayout = false;

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    if (!isLayout) {
        isLayout = true;
        if (mAdapter != null) {
            preparePositionData();
            if (mIndicator != null) {
                mIndicator.onPositionDataProvide(mPositionDataList);
            }
            if (mReselectWhenLayout && mNavigatorHelper.getScrollState() == ScrollState.SCROLL_STATE_IDLE) {
                onPageSelected(mNavigatorHelper.getCurrentIndex());
                onPageScrolled(mNavigatorHelper.getCurrentIndex(), 0.0f, 0);
            }
        }
    }
}`

不知道这种修改方式是否合理,请作者评估修改下。

sunny-zhang-98 commented 2 years ago

我也出现了这个情况,会导致Tab不断的恢复初始状态 最后通过修改这个属性暂时解决了 mReselectWhenLayout 我不知道作者在这个字段注释中说的极端情况是什么情况 https://github.com/hackware1993/MagicIndicator/blob/e14fa79267c1977b0f51f593598ad50b2d08d11a/magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/CommonNavigator.java#L52

joymingchen commented 2 years ago

其实也可以用onLayout中的(boolean changed)这个字段来进行判断

zguop commented 2 years ago

有人发布解决这个问题吗

amosxb commented 2 years ago

没人fork一下项目么

hackware1993 commented 2 years ago

没人fork一下项目么

很多人 fock 啊,出了什么问题?