无法将高度设置为自定义选项卡布局
Not able to set height to custom made tab layout
我想为我的应用程序创建自定义选项卡布局。问题是我无法设置相同的高度。
请帮忙解决问题。
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/tab_height"
android:background="@color/colorAccent"/>
custom_tab.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/tabIcon"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:background="@drawable/white_circle"
android:gravity="center"
android:text="2"
android:textColor="@color/colorAccent"/>
</FrameLayout>
<TextView
android:id="@+id/tabName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/tab_text_selection_states"
android:textSize="14sp"/>
</LinearLayout>
不要将 android:layout_height="wrap_content"
用于 TabLayout。只需使用 android:layoutHeight="@dimen/tab_height"
。您的 FrameLayout 也是如此。
在 TabLayout 中将 android:layout_height="wrap_content"
更改为 android:layout_height="100dp"
或您想要的 dps。
我想为我的应用程序创建自定义选项卡布局。问题是我无法设置相同的高度。
请帮忙解决问题。
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/tab_height"
android:background="@color/colorAccent"/>
custom_tab.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/tabIcon"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:background="@drawable/white_circle"
android:gravity="center"
android:text="2"
android:textColor="@color/colorAccent"/>
</FrameLayout>
<TextView
android:id="@+id/tabName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/tab_text_selection_states"
android:textSize="14sp"/>
</LinearLayout>
不要将 android:layout_height="wrap_content"
用于 TabLayout。只需使用 android:layoutHeight="@dimen/tab_height"
。您的 FrameLayout 也是如此。
在 TabLayout 中将 android:layout_height="wrap_content"
更改为 android:layout_height="100dp"
或您想要的 dps。