2

When Scrolling the RecyclerView, the Toolbar and the TabLayout are both collapsed as supposed, but the FloatingActionButton cut off

I followed these instructions: Hide floating button when collapsing toolbar is collapsed that suggest to add the attributes

<android.support.design.widget.FloatingActionButton
...
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="bottom|right|end" />

but my AppBarLayout is living inside another layout (xml) file => app_bar_main.xml

app_bar_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.eawedat.tabasam.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

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

images.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">



<android.support.design.widget.CoordinatorLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/imagesgallery"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />




        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fabImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right|end"
            android:layout_margin="16dp"
            android:src="@drawable/ic_image_white_24dp"
            app:backgroundTint="@color/colorPrimary" />


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

Images.java :

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int     dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 && fab.getVisibility() == View.VISIBLE) {
fab.hide();
} else if (dy < 0 && fab.getVisibility() != View.VISIBLE) {
fab.show();
}
}
});

I expect either to fully show the FloatingActionButton or to fully hide it.

enter image description here enter image description here

eawedat
  • 409
  • 2
  • 8
  • 17

0 Answers0