我有一个包含 6 个选项卡的 tablayout
。选项卡固定在显示屏中,但其文本未完全显示。我在 here 中做解决方案这样我就可以将它们概括为以下几行:
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />
但是并没有解决我的问题。我还在 here 中使用自定义 TabLayout
我仍然有同样的问题。
这是我的代码:
我将自定义 tablayout
与此 custom_tab.xml
文件一起使用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"
android:id="@+id/tabIcon"/>
<CustomViews.CustomTextView
android:id="@+id/basket_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:background="@drawable/notification_circle"
android:padding="2dp"
android:textColor="#ffffff"
android:textSize="8sp" />
<CustomViews.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/tab_inactive"
android:textSize="8sp"
android:layout_centerHorizontal="true"
android:layout_below="@id/tabIcon"
android:layout_marginBottom="2dp"
android:maxLines="1"
android:id="@+id/tabTitle"/>
</RelativeLayout>
第一个 ImageView
显示选项卡图标。下一个 ImageView
用于徽章,CustomTextView
用于显示选项卡标题。
这是我的布局文件,包括 tablayout
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabMaxWidth="0dp"
android:layoutDirection="rtl"
android:id="@+id/avatar_tabLayout"
app:tabIndicatorColor="@null"
/>
</LinearLayout>
有没有办法设置 tab
宽度和 Maximum existing tab size?还是其他解决方案?
最佳答案
努力摆脱
app:tabGravity="fill"
app:tabMode="fixed"
在你的<android.support.design.widget.TabLayout
替换为app:tabMode="scrollable"
关于Android:如何在自定义 tabLayout 中滚动填充标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50727885/