滚动时可以将TabLayout的选项卡选择指示器固定在屏幕顶部吗? [英] Can the tab selection indicator of TabLayout be pinned to the top of the screen while scrolling?

本文介绍了滚动时可以将TabLayout的选项卡选择指示器固定在屏幕顶部吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究在向下滚动时将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?

推荐答案

您应为TabLayoutAppBarLayout提供自定义Behavior(仅当TabLayoutAppBarLayout的唯一子对象时),您将在其中将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的选项卡选择指示器固定在屏幕顶部吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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