Floating Action Button not showing fully inside a fragment
Solution 1:
It's not an acceptable solution to have to show/hide the FAB whatever tab is selected. I've tried every layout combination, but moving the FAB to the activity layout was the only solution that worked. But what if you need the button only in one tab? It's the only way that works now, but I'm expecting an update of the design library since this version is too buggy. Anyway, the bottom line is that the FAB must be a direct descendant to the CoordinatorLayout, so it doesn't get pushed down by the collapsing Toolbar...
Solution 2:
You should move your FAB inside the CoordinatorLayout
.
Something like this:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_gravity="end|bottom"/>
</android.support.design.widget.CoordinatorLayout>
Then you can add the RecyclerView inside the viewPager in this way:
Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.addFragment(new RecyclerViewFragment(), "Tab1");
viewPager.setAdapter(adapter);
where the RecyclerViewFragment layout is:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Solution 3:
- I had same problem that the FloatingActionButton was completely invisible, and it was off the screen in the bottom. When I scroll down it comes up.
- Also, the tabs were getting hidden when scrolled down but I wanted them to be visible always so I fixed it by removing
app:layout_scrollFlags="scroll|enterAlways"
. Credits to JDev at how to avoid hiding the tabs when scrolled down?
This resolved the FloatingActionButton issue also, it's visible now.