Android TabLayout, Activity 选项卡始终位于中心,就像在 Play Newsstand 应用中一样

标签 android material-design android-tablayout google-play-newsstand

android.support.design.widget.TabLayout中,如何让active tab一直显示在中间,就像在Play Newsstand app中一样,如下图.

第一个和最后一个选项卡也应该出现在中心。

Play Newsstand

Play Newsstand

我尝试在 TabLayout 上使用填充。它不工作。这是我写的代码:

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@color/yellow"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="#EEE"
            app:tabMode="scrollable"
            android:gravity="bottom"
            android:clipToPadding="false"
            android:paddingLeft="90dp"
            android:paddingRight="90dp"
            />

在这种情况下,tabIndicator 也会从左侧移动 90dp。它应该保持在中心,独立于填充。

最佳答案

检查此解决方案:https://stackoverflow.com/a/36886331/651770

可以通过tabContentStart来解决,但是如果想让Tablayout的两边居中,就需要扩展这个类,手动设置padding。

关于Android TabLayout, Activity 选项卡始终位于中心,就像在 Play Newsstand 应用中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191794/

相关文章:

java - 单击按钮时以及应用程序再次启动时如何交换两个整个 Activity ,然后显示交换更改

android - 在 android 上从 gcm 迁移到 fcm

android - 从另一个 Activity 将字符串推送到数组

reactjs - 什么时候应该在 Material-UI 中使用 Typography?

android - 自定义 View 可以用作 TabItem 吗?

android - Google Play 服务投诉将过时

html - 将图像与 flex 容器中的文本对齐

android - FloatingActionButton + VectorDrawable 在 pre-Lollipop 上崩溃

java - 如何从选项卡布局中删除标高?

Android ViewPager 在 TabLayout 之上显示 View