I had the same problem in this question Floating action button that doesn't fully display inside the fragment
I have a tablayout in my Activity_main and 2 tabs (with different fragments, one of them contains recyclerView). When I put the FAB in the fragment, the FAB did not show completely until I scroll through the recyclerView.
So, I moved my FAB in the activity_main.xml file to the Coordinator_layout widget, as suggested in the related question, and it works well.
So I have a FAB in action, not in a fragment, and I would like to know how to bind, for example, my fab to a recyclerview in a fragment, for example, so that it comes to life while scrolling through recycler
Now activity_main.xml with tablayout:
activity_main.xml
<android.support.design.widget.CoordinatorLayout 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" > <android.support.design.widget.AppBarLayout android:id="@+id/appbarlayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar1" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_scrollFlags="scroll|enterAlways" android:background="?attr/colorPrimary" /> <android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/toolbar1" android:background="?attr/colorPrimary" android:scrollbars="horizontal" app:tabMode="scrollable" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" 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_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_gravity="bottom|right" android:layout_marginBottom="20dp" android:layout_marginRight="20dp" android:src="@drawable/ic_action_location_found" app:fabSize="normal" /> </android.support.design.widget.CoordinatorLayout>
fragment.xml
<RelativeLayout 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" android:padding="@dimen/activity_vertical_margin" > <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/start_button" android:scrollbars="vertical" /> </RelativeLayout>
android android-fragments android-viewpager android-recyclerview floating-action-button
ozzem
source share