1 设置 TabLayout的 android:layout_height
2 设置 app:tabPaddingBottom
比如说 你的tab文字高度是25 你想设置二者之间的间距是10
那么你android:layout_height的高度就是文本的 高度25dp 加 二者之间的距离10dp
注意不能加上indicator自身的高度5dp 因为indicator的高度是包含在 app:tabPaddingBottom里面的
这样才能实现想要的效果
android:layout_height="25dp"
app:tabPaddingBottom="10dp"
app:tabIndicatorHeight="5dp"
举个例子
<jo.android.view.JoTabLayout // 继承 com.google.android.material.tabs.TabLayout;
android:id="@+id/home_tab_layout"
style="@style/JoTabLayout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#FF0000"
android:paddingTop="10dp"
android:paddingBottom="2dp"
app:joTabs="@string/tabs_news"
app:tabIndicator="@drawable/video_tab_indicator"
app:tabIndicatorColor="#ff3d6cfb"
app:tabIndicatorHeight="4dp"
app:tabPaddingBottom="8dp" />
这里android:layout_height 设置整体高度45dp
android:paddingTop 10dp
android:paddingBottom=“2dp” + app:tabPaddingBottom=“8dp” 这两个决定了整体的paddingBottom也是10dp
indicator与自定义customView的距离是 app:tabPaddingBottom 减去 app:tabIndicatorHeight的高度
如果想设置 indicator紧挨着自定义CustomView
那么设置如下
<jo.android.view.JoTabLayout
android:id="@+id/home_tab_layout"
style="@style/JoTabLayout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#FF0000"
android:paddingTop="10dp"
android:paddingBottom="6dp"
app:joTabs="@string/tabs_news"
app:tabIndicator="@drawable/video_tab_indicator"
app:tabIndicatorColor="#ff3d6cfb"
app:tabIndicatorHeight="4dp"
app:tabPaddingBottom="4dp" />
app:tabPaddingBottom="4dp" 这里修改的跟app:tabIndicatorHeight 高度一样就可以了.
android:paddingBottom="6dp" 保证 6+4 = android:paddingTop
效果图如下
希望对大家有帮助