【发布时间】:2023-03-24 03:32:02
【问题描述】:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabIndicatorColor="@color/red"
app:tabIndicatorHeight="3dp"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_below="@+id/app_bar_layout"/>
</android.support.design.widget.CoordinatorLayout>
我已经为选项卡设置了自定义 UI:
private TabLayout mTabLayout;
for (int i = 0; i < TITLES.length; i++) {
RelativeLayout tabView = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
mTabLayout.getTabAt(i).setCustomView(tabView);
}
以下是我的自定义 UI:custom_tab.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Title"
android:textSize="14sp"/>
当我增加文本视图的上述高度时,Tablayout 的高度不会增加,并且选项卡中的自定义视图从底部截断。
我认为 Tablayout 的高度是如何固定的(可能是操作栏的高度),即使将其高度更改为“match_parent”也不起作用。
如何增加 Tablayout 的高度?有什么我做错了吗?
【问题讨论】:
-
尝试给 TabLayout 设置一个真实的高度,比如 60dp。
-
谢谢。以前,我将高度设置为“match_parent”,但这不起作用。但是在将其设置为 60dp 或 100dp 高度后会发生变化。奇怪的问题。
标签: android android-layout android-tabs