android - 如何在固定模式下将 tabLaout 的 tabitems 排列成多行?
问题描述
我想在 tabLayout 中有七个选项卡。它们将不可滚动。因此,我希望它们位于多行中。但是,在固定模式下,它们都排成一行。我找到了一些不是直接答案而是解决方法的答案。有没有办法做到这一点?
我的 XML 快照:
<com.google.android.material.tabs.TabLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorGrayStandard"
app:tabTextColor="@color/colorWhite">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wikipedia" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wikia" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/youtube" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/goodreads" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/imdb" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yelp" />
</com.google.android.material.tabs.TabLayout>
解决方案
这是 TabLayout 的文档:https ://developer.android.com/reference/com/google/android/material/tabs/TabLayout
TabLayout 提供了一个水平布局来显示选项卡。
这是文档中写的第一行,它是您对这个问题的回答。
TabLayout 无法做到这一点。您可以使它们可滚动,仅此而已。您可以创建和使用许多解决方法而不会出现问题。
在上面的文档中,您可以找到使用 TabLayout 实际可行的任何内容。如果您想创建解决方法,只需自己创建固定选项卡,创建侦听器,并在选项卡更改时使用片段来更改您想要的视图。
推荐阅读
- animation - Xamarin 窗体形状动画
- python - Python用单词列表替换部分url
- flutter - 回调函数不适用于自定义键
- python - 加载 PyQt5 窗口后如何让 tts (pyttsx3) 说话
- qt - QGroupBox 将背景限制在其窗格中
- php - 如何在管理面板中创建菜单以管理 wordpress 侧边栏中的内容
- node.js - 如何将 npm 模块的系统级依赖项与电子应用程序的模块本身捆绑在一起?
- android - Android Studio appcompat 支持库
- javascript - 在 iframe 之间共享源
- android - Android 协程和 LiveData