【问题标题】:Text gets cut off in tablayout tab文本在 tablayout 选项卡中被截断
【发布时间】:2018-09-12 21:17:42
【问题描述】:

我在我的 android 应用程序中使用了一个 tablayout,它可以扩展自定义选项卡并使用图标对其进行设置。由于空间不足,其中一个选项卡的文本被截断。我必须使文本非常小才能完全显示。这是我的标签布局的设置方式。

        <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_width="match_parent"
        android:layout_height="@dimen/custom_tab_layout_height"
        app:tabMode="fixed"
        app:tabGravity="fill" />

自定义选项卡布局如下所示:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_text"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="?attr/selectableItemBackground"
    android:gravity="center"
    android:textSize="8dip"
    android:textColor="#ffffff"
    android:singleLine="true"/>

这是我为标签设置文本和图标的代码:

            TextView tabOne = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
        tabOne.Text = "Home";
        tabOne.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.homewhite, 0, 0);
        tabLayout.GetTabAt(0).SetCustomView(tabOne);

        TextView tab2 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
        tab2.Text = "Inbox";
        tab2.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.messageWhite, 0, 0);
        tabLayout.GetTabAt(1).SetCustomView(tab2);

        TextView tab3 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
        tab3.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.upload_icon, 0, 0);
        tabLayout.GetTabAt(2).SetCustomView(tab3);

        TextView tab4 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
        tab4.Text = "Notification";
        tab4.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.notifWhite, 0, 0);
        tabLayout.GetTabAt(3).SetCustomView(tab4);

        TextView tab5 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
        tab5.Text = "Profile";
        tab5.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.profWhite, 0, 0);
        tabLayout.GetTabAt(4).SetCustomView(tab5);

如果我把文本变大,tablayout 看起来像这样

如何让全文显示?如果我使 tablayout 可滚动,那么当我单击选项卡时它会左右移动。 任何帮助表示赞赏。

【问题讨论】:

    标签: android tabs android-tablayout


    【解决方案1】:

    即使值为零,也尝试使用填充,
    app:tabPaddingStart="0dp" app:tabPaddingEnd="0dp"
    请检查这个sn-p,这解决了我的问题。

     <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="@dimen/tablayout_height"
            app:tabGravity="fill"
            app:tabIndicatorHeight="0dp"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/black"
            app:tabTextColor="@color/pure_white"
            app:tabPaddingStart="0dp"
            app:tabPaddingEnd="0dp"/>
    

    【讨论】:

      【解决方案2】:

      问题是没有足够的空间来显示文本。如果我是你,我会尽可能地减小中间按钮的大小,看看它是否给你足够的空间。在最坏的情况下,您可以删除文本(图标非常简单)或缩小文本大小。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-29
        • 1970-01-01
        • 1970-01-01
        • 2016-01-06
        • 2015-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多