Reputation: 771
Is it possible to show Floating Action Button when all RecyclerView items fit screen. The problem is - when Floating Action Button is hidden and RecyclerView becomes almost empty - there is no place to scroll and so Floating Action Button not shown.
Upvotes: 1
Views: 3398
Reputation: 771
I have solved my problem in such way:
After data have changed I am registering ViewTreeObserver.OnPreDrawListener
on recyclerView
private RecyclerView.AdapterDataObserver adapterDataObserver = new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
recyclerViewEmptySupport.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
recyclerViewEmptySupport.getViewTreeObserver().removeOnPreDrawListener(this);
scrollingFABBehavior.recyclerViewChanged(recyclerViewEmptySupport, dialogsListAdapter, fab);
return false;
}
});
}
};
In this listener I inform FAB that recyclerView MAY be empty enough (or may be not) to forcely be shown
Upvotes: 0
Reputation: 697
You can achieve the desired behavior by using a Coordinator Layout. The below links are pretty good references to start with.
https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/
https://medium.com/ribot-labs/exploring-the-new-android-design-support-library-b7cda56d2c32
Upvotes: 2
Reputation: 5829
Yes you have to use co-ordinate layout like this https://lab.getbase.com/introduction-to-coordinator-layout-on-android/
Upvotes: 2