Android 更改所选选项卡项高度
我正在使用TabLayout,并且我正在寻找一种方法来更改所选TabItem的高度,所以这一个会比其他的大。我尝试使用TabIndicator,但我只能改变它的颜色和大小,而不能改变它的位置(它总是在TabLayout中,我需要将它放在它的正上方,以达到我需要的效果) 有没有一种方法可以使用选择器或在布局xml本身中实现这一点 下面是所需效果的示例(左侧为所选选项卡): 这是我目前掌握的代码:Android 更改所选选项卡项高度,android,xml,layout,tabs,Android,Xml,Layout,Tabs,我正在使用TabLayout,并且我正在寻找一种方法来更改所选TabItem的高度,所以这一个会比其他的大。我尝试使用TabIndicator,但我只能改变它的颜色和大小,而不能改变它的位置(它总是在TabLayout中,我需要将它放在它的正上方,以达到我需要的效果) 有没有一种方法可以使用选择器或在布局xml本身中实现这一点 下面是所需效果的示例(左侧为所选选项卡): 这是我目前掌握的代码: <android.support.constraint.ConstraintLayout xm
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorHeight="0dp"
app:tabBackground="@drawable/nav_item_color_state">
<android.support.design.widget.TabItem
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 1"/>
<android.support.design.widget.TabItem
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 2"/>
</android.support.design.widget.TabLayout>
</android.support.constraint.ConstraintLayout>
最后,我使用了两个按钮,创建了两个不同的绘图表,在它们的背景中用作选定/未选定状态。一点也不优雅,但它确实有效。尝试在您的表格布局上使用android:clipChildren=“false”
,并通过编程更改高度。