0

I want, that my BottomApp bar is in bottom parent layout, but for some reason he jumps up to the indicator, although setting parameter layout_gravity = bottom my xml file

<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>

enter image description here

2 Answers2

0

You need to know about the coordinator layout for android. Suppose you have two views beside one another or top. When you use coordinator layout when one of the views changes its location, the second one will also change if it tries to overlap this. So, like above you need to use coordinator layout for your design.

-1

What you should do is put everything inside 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>
Mbuodile Obiosio
  • 1,463
  • 1
  • 15
  • 19