我以前看过this post时也遇到了同样的问题,但是最近Google推出了另一个TabLayout
问题:有没有一种方法,例如,使用attribute或其他Google可维护的方法来减少文本和图标之间的间距,从而避免必须通过文本和图标创建单独的布局?
我当前的布局如下:
<androidx.viewpager.widget.ViewPager
android:id="@+id/mViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/homeTabs">
<com.google.android.material.tabs.TabLayout
style="@style/Widget.MaterialComponents.TabLayout"
android:id="@+id/homeTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:tabIndicatorColor="@color/clear_blue">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/one_svg"
android:text="@string/one"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/two_svg"
android:text="@string/two"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/three_svg"
android:text="@string/three"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/four_svg"
android:text="@string/four"/>
</com.google.android.material.tabs.TabLayout>
我经过一些测试后就明白了,no。
[Google Tab项的创建是为了与材料设计规则匹配,因此,图标和文本之间的间距是根据该规则计算的,您可以在报告的帖子中阅读here。
[唯一的方法是使用ImageView和TextView创建自定义布局,并在TabItem中将其展开。
我建议您这样,因为可以完全自定义,因此您可以实际创建所需的内容。
希望我帮了你!如果您有任何问题,请写评论。