为什么图像在TabLayout的中央?

问题描述 投票:0回答:1

我针对不同的屏幕尺寸进行了不同的设计。普通的屏幕尺寸图像看起来像我想要的样子。我遇到了此错误,无法找到解决方案。更改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个回答
0
投票

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" />
© www.soinside.com 2019 - 2024. All rights reserved.