Android Bottomappbar with Framelayout and Coordinatorlayout

Asked

Viewed 54 times

-1

I have a problem in Framelayout the working is correct, but Framelayout is with the starting position of Top above Appbarlayout, according to image:

Imagem do problema

Below the code of Main, where the base is.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activity.MainActivity">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <FrameLayout
            android:id="@+id/containerMain"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toTopOf="@+id/bottomAppBar"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </ScrollView>

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorMenu"
        android:theme="@style/CvTheme"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:translationZ="0.1dp"
        app:elevation="0dp">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@drawable/ic_bgbranco"
            android:theme="@style/CvTheme"
            app:popupTheme="@style/CvTheme" />

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

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" >
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:menu="@menu/app_bar_menu" />
    </com.google.android.material.bottomappbar.BottomAppBar>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="176dp"
        android:layout_marginEnd="24dp"
        android:layout_gravity="center_horizontal"
        app:layout_constraintBottom_toTopOf="@+id/fab1"
        android:background="?android:attr/selectableItemBackground"
        android:clickable="true"
        android:elevation="16dp"
        android:focusable="true"
        android:visibility="invisible"
        app:backgroundTint="#ffffff"
        app:pressedTranslationZ="12dp"
        app:srcCompat="@drawable/ic_add" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="106dp"
        android:layout_marginEnd="24dp"
        android:layout_gravity="center_horizontal"
        app:layout_constraintBottom_toTopOf="@+id/fab"
        android:background="?android:attr/selectableItemBackground"
        android:clickable="true"
        android:elevation="16dp"
        android:focusable="true"
        android:visibility="invisible"
        app:backgroundTint="#ffffff"
        app:pressedTranslationZ="12dp"
        app:srcCompat="@drawable/ic_add" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@+id/bottomAppBar"
        app:srcCompat="@drawable/ic_add"
        app:backgroundTint="@color/colorAccent" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I use Recyclerview to create list content:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragment.LeadsFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerAdapterLeads"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

The question is how best to do this?

1 answer

0


The problem is that the AppBarLayout is below the ScrollView (containing the FrameLayout) in the component hierarchy. Create an ID for the AppBarLayout (for example android:id="@+id/appBarLayout") and within the tag of the ScrollView place the attribute app:layout_constraintTop_toBottomOf and pass the created ID. Example: app:layout_constraintTop_toBottomOf="@id/appBarLayout".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.