Java 表格布局中点之间的间距
我有一个带有2个标签的TabLayout的片段。每个选项卡都用一个点填充,以表示viewpager中的页面 我如何设置两个标签之间的空格/填充/边距,其中有点 我尝试了几件事,但都不管用 谢谢你的帮助:) fragment.xml:Java 表格布局中点之间的间距,java,android,Java,Android,我有一个带有2个标签的TabLayout的片段。每个选项卡都用一个点填充,以表示viewpager中的页面 我如何设置两个标签之间的空格/填充/边距,其中有点 我尝试了几件事,但都不管用 谢谢你的帮助:) fragment.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<androidx.viewpager.widget.ViewPager
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/pager"
/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabDots"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="7.5dp"
app:tabBackground="@drawable/dot_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
android:layout_marginBottom="20dp"
app:tabMaxWidth="7.5dp"
/>
</RelativeLayout>
dot_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/dot_selected"
android:state_selected="true"/>
<item android:drawable="@drawable/dot_default" />
</selector>
dot_selected.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
android:innerRadius="0dp"
android:shape="rectangle"
android:useLevel="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorBlack"/>
<corners android:radius="1000dp"/>
</shape>
dot_default.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
android:innerRadius="0dp"
android:shape="rectangle"
android:useLevel="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorGrey"/>
<corners android:radius="1000dp"/>
</shape>
使用如下填充:
app:tabPaddingStart="10dp"
app:tabPaddingEnd="10dp"
您正在使用
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabDots"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="7.5dp"
app:tabBackground="@drawable/dot_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
android:layout_marginBottom="20dp"
app:tabMaxWidth="7.5dp" //here is the problem
/>
增加tabMaxWidth,使点之间有所需的间距。我尝试过,但点仍然粘在一起。您知道另一种解决方法吗?您是否添加了重力和表格布局模式,如app:tabMode=“fixed”app:tabGravity=“fill”和app:tabIndicatorFullWidth=“false”。同时在28中更新您的支持库版本。它适合我。@NilsKyuubi,如果它服务完美,你能提出正确的解决方案吗。谢谢