根据下面的链接设置完距离后无法生效

https://www.jb51.net/article/131304.htm

 

  layout

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabDots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="-100dp"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorGravity="center"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabMaxWidth="80dp"
app:tabMinWidth="20dp"
app:tabPaddingStart="20dp"
app:tabPaddingEnd="20dp"
/>


tab_selector.xml
xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/selected_dot" android:state_selected="true" />

<item android:drawable="@drawable/default_dot" />

</selector>

selected_dot.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadius="0dp"
android:shape="ring"
android:thickness="8dp"
android:useLevel="false">
<solid android:color="#FFFFFF"/>
</shape>
</item>
</layer-list>
default_dot.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadius="0dp"
android:shape="ring"
android:thickness="8dp"
android:useLevel="false">
<solid android:color="#66FFFFFF"/>
</shape>
</item>
</layer-list>


把下面这四个属性设置后就好了
app:tabMaxWidth="80dp"
app:tabMinWidth="20dp"
app:tabPaddingStart="20dp"
app:tabPaddingEnd="20dp"

 

 

版权声明:本文为mwl523原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/mwl523/p/13606297.html