【问题标题】:Why are images in the centre on TabLayout?为什么图像在 TabLayout 的中心?
【发布时间】:2020-06-06 04:54:42
【问题描述】:

我为不同的屏幕尺寸做了不同的设计。正常屏幕尺寸的图像看起来像我想要的那样。我遇到了这个错误,找不到解决方案。 更改 Tablayout 的大小不起作用。enter image description here

enter image description here

我在两个设计中使用相同的代码

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:theme="@style/AppBarOverlay">

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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="80dp"
        android:background="@drawable/banner"
        app:layout_anchor="@+id/appBarLayout"

        app:layout_anchorGravity="center"
        app:tabIndicatorColor="#00b7fa">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/buyutec50" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/plus50" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/table50" />

    </com.google.android.material.tabs.TabLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

    标签: android xml tabs android-tablayout


    【解决方案1】:

    app:tabMaxWidth="0dp" 添加到所有标签项。

    <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:tabMaxWidth="0dp"
                android:icon="@drawable/buyutec50" />
    

    【讨论】:

      猜你喜欢
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 2021-06-23
      相关资源
      最近更新 更多