Android : 如何更改选项卡布局中各个选项卡的宽度?

Android : How to change width of individual tabs in tab layout?

我正尝试在选项卡布局的开头调整通知选项卡的大小,如图所示,

到现在为止,除了宽度之外,我可以将所有三个选项卡都设置为如图所示。我目前的进度如下,

所以我的问题是,如何调整选项卡布局中各个项目的大小? 我搜索了很多页面并尝试阅读文档,但没有找到任何有用的东西。

提前致谢。

你可以试试这个 TabLayout。

layout.xml 文件

  <android.support.design.widget.TabLayout
        android:id="@+id/tabCauses"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/white"
        app:tabTextAppearance="@style/MyCustomTextAppearance" />

style.xml 文件

  <style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
    <item name="android:background">#FF26221E</item>
    <item name="android:fontFamily">@font/montserrat_semibold_1</item>
</style>

虽然迟到了,但迟到总比不到好。我也看不出 Parth Patel 的回答与这个问题有什么关系。 看看this,你会找到你要找的东西。

LinearLayout layout = ((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(YOUR_TAB_NUMBER));
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams();
layoutParams.weight = YOUR_WEIGHT; // e.g. 0.5f
layout.setLayoutParams(layoutParams);