【发布时间】: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