Ahm*_*aba 3 tabs android android-tablayout
我在我的 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" />
Run Code Online (Sandbox Code Playgroud)
自定义选项卡布局如下所示:
<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"/>
Run Code Online (Sandbox Code Playgroud)
这是我设置选项卡文本和图标的代码:
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);
Run Code Online (Sandbox Code Playgroud)
如果我将文本放大,则选项卡布局如下所示
如何让全文显示?如果我使选项卡布局可滚动,那么当我单击选项卡时,它会左右移动。任何帮助表示赞赏。
小智 6
即使值为零,也尝试使用填充,
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
请检查此代码片段,这解决了我的问题。
<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"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3599 次 |
| 最近记录: |