自定义 tabLayout 徽章视图被截断 [Android]

Custom tabLayout badge view getting cut off [Android]

对于选项卡布局,正在扩展自定义布局 custom_tab.xml,如果名称的长度增加,徽章视图将被截断。

我已经尝试了wrap_content所有的浏览量,还是没有效果

这是custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="48dp"
              android:layout_margin="5dp"
              android:orientation="horizontal">

    <TextView

        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="title"
        android:textColor="@color/white"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView

        android:id="@+id/tv_count"
        android:layout_width="31dp"
        android:layout_height="31dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@drawable/badge_drawable"
        android:gravity="center"
        android:textColor="#000000"
        android:textSize="12sp" />

</LinearLayout>

这是 java 用于为 tablayout 扩充视图的代码

private void setupTabIcons() {
    for (int i = 0; i < NewFragment.categories.size(); i++) {
        try {
            LinearLayout currentTabLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);

            ..............................
            ..............................

            tabLayout.getTabAt(i).setCustomView(currentTabLayout);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

文本的屏幕截图增加了单行设置为 false 的长度

文本的屏幕截图增加了长度,单行设置为 true

这两种情况都会从布局中删除徽章视图 我希望文本视图是单行的。

谁能帮我解决这个问题。

如有任何帮助或建议,我们将不胜感激。

谢谢

通过在标签

下的 dimens.xml 文件下将宽度设置为更高级别解决了问题
<dimen name="tab_max_width">XXXdp</dimen>