gpt4 book ai didi

android - 当 tabMode 设置为 'scrollable' 时,TabLayout 不填充宽度

转载 作者:IT王子 更新时间:2023-10-28 23:59:44 25 4
gpt4 key购买 nike

我已将 TabLayout(来自支持库 v22.2.1)添加到我的 fragment 中:

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MyColorAccentTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>

问题是当 Fragment 的方向是横向时(在最初创建 Fragment 之前或之后),TabLayoutFragment 的宽度不匹配(是的,父级的宽度也设置为 match_parent)。

当屏幕宽度较小时(即不能同时显示所有选项卡): enter image description here

当屏幕宽度足够大以显示所有选项卡时(请参阅右侧的空白区域): enter image description here

如果我将 tabMode 更改为固定,则会填充宽度但选项卡太小。有没有合适的解决方案?

最佳答案

androidx 版本:

<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
/>
</androidx.viewpager.widget.ViewPager>

With more than 5 tabs

***** 下面是旧答案 *****

试试这个,这是一种设置 tabMaxWidth="0dp"tabGravity="fill"tabMode="fixed" 的解决方法.

 <android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.v4.view.ViewPager>

10 英寸平板电脑上的屏幕截图:

screenshot

关于android - 当 tabMode 设置为 'scrollable' 时,TabLayout 不填充宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32601414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com