Float Action Button is not fixed in the footer with Collapsing ActionBar / Toolbar

0

I have a fragment with coordinator layout, recyclerview and a Float Action Button, and in the view that calls that fragment has a tablayout that hides and appears as it goes up or down the recycler view, I tried in several ways to leave the fab fixed in the footer , but anyway it always goes up when sliding the recycler view

belowisthefragmentcode:

<FrameLayoutxmlns: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/frmLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.julioantonini.meuchat.ContatosFragment">


<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerContatos"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="70dp"
    android:layout_marginRight="10dp"
    android:layout_marginEnd="10dp"
    app:elevation="1dp"
    app:srcCompat="@drawable/ic_action_add"
    app:layout_anchor="@id/recyclerContatos"
    app:layout_anchorGravity="bottom|right|end"/>

and below the activity code:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />


    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        app:tabIndicatorColor="@color/colorTab"/>

</android.support.design.widget.AppBarLayout>


<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@id/appbar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    
asked by anonymous 27.10.2017 / 01:02

1 answer

0

If you have no problem putting your FAB into activity , you can do this:

...
<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@id/appbar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="70dp"
    android:layout_marginRight="10dp"
    android:layout_marginEnd="10dp"
    app:elevation="1dp"
    app:srcCompat="@drawable/ic_action_add"
    app:layout_anchor="@id/viewPager"
    app:layout_anchorGravity="bottom|right|end"/>

What changes here is that layout_anchor of your FAB ceases to be RecyclerView and becomes ViewPager . In addition, of course, remove FAB from the layout of your fragment and move to activity .

    
27.10.2017 / 04:36