我的浮动操作按钮显示不正确...?

时间:2021-03-22 07:20:39

标签: android floating-action-button bottomnavigationview android-bottomappbar

我正在使用 TAB LAYOUTView PagerBOTTOM APP BAR 以及用于底部导航的浮动操作按钮,但我认为我的浮动操作按钮显示在视图寻呼机下,因此它看起来像是从上方切下的....请帮我解决这个问题

这是我的 XML 代码....

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_main_bg"
    tools:context=".home.HomeActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_navigation_bg"
            app:fabCradleRoundedCornerRadius="0dp"
            app:backgroundTint="@color/color_primary"
            />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:backgroundTint="@color/color_primary"
            app:srcCompat="@drawable/ic_plus"
            app:layout_anchor="@id/bottomAppBar"
            android:contentDescription="@string/add_item_to_this_destination" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_primary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:tabIndicatorColor="@color/color_secondary"
        app:tabSelectedTextColor="@color/color_secondary"
        app:tabTextColor="@color/color_secondary" />

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager_2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/coordinator_layout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tab_layout">

    </androidx.viewpager2.widget.ViewPager2>

</androidx.constraintlayout.widget.ConstraintLayout>

这是它的样子

enter image description

2 个答案:

答案 0 :(得分:0)

问题是因为 CoordinatorLayout

解决方案 1: 添加

android:clipToPadding="false"
android:clipChildren="false"

在 CoordinatorLayout 中

解决方案 2: 将 CoordinatorLayout 作为父布局并将所有子布局放入其中。

解决方案 3:

在 view_pager_2 中 添加

            android:layout_marginBottom="?actionBarSize"

解决方案 4: 将此行添加到您的晶圆厂

android:elevation="10dp"

答案 1 :(得分:0)

将以下代码添加到您的 BootomAppBar 标签:

    app:fabAlignmentMode="center"
    app:fabCradleMargin="8dp"

所以它会变成:

 <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bottom_navigation_bg"
        app:fabCradleRoundedCornerRadius="0dp"
        app:backgroundTint="@color/color_primary"
        app:fabAlignmentMode="center"
        app:fabCradleMargin="8dp"
        />
相关问题