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

2

1

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?

enter image description here

Lurette answered 27/6, 2015 at 7:40 Comment(1)
Set minHeight of the CollapsingToolbarLayout to height of the indicator (4dp for example) and make sure exitUntilCollapsed is in its layout_scrollFlags property.Schaefer
E
0

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.

Electromechanical answered 27/6, 2015 at 8:11 Comment(1)
I want the tablayout to move out except the indicator bar on the bottom of tablayout.Lurette
C
0

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).

Conchiolin answered 27/6, 2015 at 14:51 Comment(1)
Thanks for your answer. But, I can't get it perfectly. Sorry. Could you give me more hints?Lurette

© 2022 - 2024 — McMap. All rights reserved.