【发布时间】:2021-07-15 22:34:07
【问题描述】:
我一直在 Fragment 中使用 TabLayout,并且 TabLayout 项目在图像中显示如下
这是我输入使用此 XML 代码的时候。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@color/black"
app:tabMode="scrollable"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab One"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab Two"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab Three"/>
</com.google.android.material.tabs.TabLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
当我从 XML 中删除 'app:tabMode="scrollable"' 时,布局看起来像这样。 我尝试清理项目。清除缓存,尝试安装 .gradle。这些都不起作用。
有人可以帮忙解决这个问题。谢谢
【问题讨论】:
-
你想在片段中创建不同的标签吗?
-
不只有一个 TabLayout。当我将 TabLayout 放置在片段或 Activity 样式布局中时,选项卡将像这样显示。
标签: android xml material-design android-tablayout