0

我想要,我的 BottomApp 栏位于底部父布局中,但由于某种原因,他跳到指示器,尽管设置参数 layout_gravity = 底部我的 xml 文件

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
    <include
        layout="@layout/toolbar"/>
<androidx.viewpager.widget.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="500dp"
    android:layout_marginBottom="16dp">

    <com.itsronald.widget.ViewPagerIndicator
        android:id="@+id/view_pager_indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:gravity="center_vertical"/>
</androidx.viewpager.widget.ViewPager>

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/main_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        style="@style/bottom_app_bar_style"
        app:fabAlignmentMode="center"
        app:menu="@menu/menu"
        android:layout_gravity="bottom"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        style="@style/fab_style"
        android:src="@drawable/ic_plus"
        app:layout_anchor="@id/bottom_app_bar"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

在此处输入图像描述

4

2 回答 2

0

您应该做的是将所有内容放入 CoordinatorLayout

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/main_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom">

<androidx.appcompat.widget.Toolbar
             android:id="@+id/toolbar"
             android:layout_width="match_parent"
             android:layout_height="?attr/actionBarSize"
             android:background="?attr/colorPrimary"
             android:elevation="4dp"
             app:popupTheme="@style/AppTheme.PopupOverlay"/>

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        style="@style/bottom_app_bar_style"
        app:fabAlignmentMode="center"
        app:menu="@menu/menu"
        android:layout_gravity="bottom"/>
 </androidx.constraintlayout.widget.ConstraintLayout>

//Use a relative layout to put your indicator here

</androidx.coordinatorlayout.widget.CoordinatorLayout>
于 2019-07-07T09:59:17.757 回答
0

您需要了解 android 的协调器布局。假设您有两个并排或顶部的视图。当您在其中一个视图更改其位置时使用协调器布局时,如果第二个视图尝试与此重叠,它也会更改。因此,像上面一样,您需要为您的设计使用协调器布局。

于 2019-07-07T11:16:58.397 回答