【问题标题】:tab icons not filling full width选项卡图标未填充全宽
【发布时间】:2020-02-03 00:28:28
【问题描述】:

我尝试了几种解决方案,但都没有奏效。在某些设备上,标签栏不会填满父级的宽度。它适用于三星 Tab 2 等设备,但不适用于像素 2 等设备(如所附图像)。

<android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabTextAppearance="@style/MyTabLayoutTextAppearance"
        app:layout_constraintBottom_toBottomOf="parent"
        app:tabIndicatorColor="@color/colorBackground"
        app:tabMode="scrollable"
        app:tabMaxWidth="0dp"
        app:tabGravity="fill"
        app:tabSelectedTextColor="@color/colorPrimary"
        />

`

【问题讨论】:

  • 试试app:tabGravity="fill"

标签: android android-support-library android-tablayout material-components-android android-support-design


【解决方案1】:

您还必须使用 app:tabMode="fixed" 属性。
比如:

  <com.google.android.material.tabs.TabLayout
      app:tabGravity="fill"
      app:tabMode="fixed"
      ..>

还要检查doc: 在支持设计库中:

重力用来尽可能地填充TabLayout。此选项仅在与MODE_FIXED 一起使用时才生效

Material Components Library

重力用来尽可能地填充TabLayout。此选项仅在与MODE_FIXED 一起在小于600dp 宽的非横向屏幕上使用时生效。

【讨论】:

    【解决方案2】:

    使用fixedtabMode 代替scrollable

    app:tabMode="fixed"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 2021-09-20
      • 2021-09-02
      • 1970-01-01
      • 2013-01-10
      相关资源
      最近更新 更多