Can the tab selection indicator of TabLayout be pinned to the top of the screen while scrolling?

我的未来我决定 提交于 2019-12-13 01:53:44

问题


I am investigating the way to pin the tab indicator of TabLayout in CoordinatorLayout while scrolling down.

If I add scroll|enterAlwaysCollapsed flag to the TabLayout, then the tablayout itself is dissappeared while scrolling down. I want tab indicator bar be pinned to the top of the screen.

Is there a way to implement this?


回答1:


I think you should just have no flags at all. Your layout should be something like:

<CoordinatorLayout>
    <AppBarLayout>

        <Toolbar app:layout_scrollFlags="scroll|enterAlways" />
        <TabLayout/>

    </AppBarLayout>

    < /> <!-- ViewPager or other stuff -->
</CoordinatorLayout>

If you assign the scroll flag to the TabLayout it will start reacting to scroll gestures and will move/enter/exit according to your flags. As far as I understand about your question, you don't want it to move, so just remove the flags.

See here for reference.




回答2:


You should provide your custom Behavior for your TabLayout or AppBarLayout (only if TabLayout is only child of the AppBarLayout), where you will translate the y of the TabLayout to the -mTabLayout.getHeight() + mTabIndicatorHeight. You should do the same if you go with offseting top and bottom.

Currently, TabLayout does not have @DefaultBehavior and it is translated by the AppBarLayout behavior. Which is plain top and bottom offseting to the total amount of scroll range (sum of heights of views that have scrolling flags).



来源:https://stackoverflow.com/questions/31086356/can-the-tab-selection-indicator-of-tablayout-be-pinned-to-the-top-of-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!