问题描述
我正在研究在向下滚动时将TabLayout
的制表符固定在CoordinatorLayout
中的方法.
I am investigating the way to pin the tab indicator of TabLayout
in CoordinatorLayout
while scrolling down.
如果在TabLayout
上添加scroll|enterAlwaysCollapsed
标志,则向下滚动时将不显示布局.我希望将标签指示栏固定在屏幕顶部.
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?
推荐答案
您应为TabLayout
或AppBarLayout
提供自定义Behavior
(仅当TabLayout
是AppBarLayout
的唯一子对象时),您将在其中将TabLayout
的y转换为-mTabLayout.getHeight() + mTabIndicatorHeight
.如果要偏移顶部和底部,则应该执行相同的操作.
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.
当前,TabLayout
没有@DefaultBehavior
,并且通过AppBarLayout
行为进行翻译.它是顶部和底部的纯偏移量,偏移量为滚动范围的总和(具有滚动标记的视图的高度之和).
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).
这篇关于滚动时可以将TabLayout的选项卡选择指示器固定在屏幕顶部吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!