【问题标题】:Custom tabLayout badge view getting cut off [Android]自定义 tabLayout 徽章视图被切断 [Android]
【发布时间】:2017-02-09 06:11:18
【问题描述】:

对于选项卡布局,我正在夸大自定义布局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>

这是为 tablayout 膨胀视图的 java 代码

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 的文本长度增加的屏幕截图

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

谁能帮我解决这个问题。

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

谢谢

【问题讨论】:

  • 嗨,Sanoop,您可以尝试使用“marquee”属性设置为一行,因为您的文本很长
  • @DileepPatel 感谢您的回复,我已经尝试过,但对徽章视图影响不大,仍然隐藏在视图中
  • 我想如果文本太长而无法放入是不可能的,如果模式设置为“固定”,标签布局将尝试适应 3 个标签,我不得不缩小文本以满足相同的要求
  • 目前有 7 个标签。及其可滚动的。其他标签标题没有问题。如果我将文本长度设置为更高,那就是这个。 @hardikm
  • 好的,会尝试制作这个用户界面

标签: android view android-tablayout


【解决方案1】:

通过在标签下的 dimens.xml 文件中将宽度设置为更高级别来修复问题

<dimen name="tab_max_width">XXXdp</dimen>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2021-02-13
    相关资源
    最近更新 更多