TabLayout的tab文字和indicator之间的距离设置

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
  
  效果图如下

在这里插入图片描述
希望对大家有帮助

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值