Android 调整表格布局标题文本和图标之间的高度

Android 调整表格布局标题文本和图标之间的高度,android,material-design,android-tablayout,Android,Material Design,Android Tablayout,我想没有任何方法可以缩短标题文本和TabLayout图标之间的距离,就像Google plus中的图标和文本标题至少没有距离一样。我已经找过了,但到现在还是找不到 已编辑 这是我设置图标和标题的方式: tabLayout.getTabAt(3).setIcon(R.drawable.ic_more_horiz_white_24dp); tabLayout.getTabAt(3).setText("More"); 这是我的表格布局: <android.support.design.w

我想没有任何方法可以缩短标题文本和
TabLayout
图标之间的距离,就像Google plus中的图标和文本标题至少没有距离一样。我已经找过了,但到现在还是找不到

已编辑

这是我设置图标和标题的方式:

 tabLayout.getTabAt(3).setIcon(R.drawable.ic_more_horiz_white_24dp);
 tabLayout.getTabAt(3).setText("More");
这是我的
表格布局

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="@color/white"
        app:tabIndicatorHeight="2dp"
        app:tabTextAppearance="?android:attr/textAppearanceSmall"
        />

引入了TabLayout
,以帮助开发人员遵守材料设计标准。在这种情况下,它是适当的选项卡高度,在图标和文本之间填充,以及图标和文本大小。调查以熟悉他们

但是,如果您确实不喜欢填充(并且不希望根据材质设计指南构建应用程序),您可以更改它

你可以用。这样你就可以通过你的布局

但是请记住,如果您想更动态地构建
TabLayout
并使用它的
TabLayout.Tab#setText(java.lang.CharSequence)
TabLayout.Tab#setIcon(int)
您必须使用这样的布局:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/icon"/>
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:id="@android:id/text1"
    android:gravity="center"
    android:layout_below="@android:id/text1" />


查看标识符
@android:id/icon
@android:id/text1
。如果添加这些ID,则
TabLayout
您的布局将使用
TabLayout
类代码。有关更多信息,请查看。

您可以尝试此代码,它适合我

for (i in 0 .. tabLayout.tabCount) {
        val params = tabLayout.getTabAt(i)?.view?.getChildAt(0)?.layoutParams as LinearLayout.LayoutParams?
        params?.bottomMargin = 0
        tabLayout.getTabAt(i)?.view?.getChildAt(0)?.layoutParams = params
    }

您是否为您的表格布局使用任何自定义布局?您找到了解决方案吗?您找到了解决方案吗?有解决方案吗?当然,让我试试这个。您使用“权重”,它仅适用于LinearLayout父级,您也使用“layout_below”,它仅适用于RelativeLayout父级。我认为这应该是包装在线性布局和“布局_以下”属性可以删除。谢谢!你的回答帮助了我+1如何在使用MVVM和数据绑定时实现这一点?感谢谷歌,这是一个多么简单的解决方案。