I have an AppBarLayout
that scrolls off screen when scrolling a RecyclerView
.
Below the RecyclerView
there is a RelativeLayout
that is a footer.
The footer is shown only after scrolling up - it behave like it has
layout_scrollFlags="scroll|enterAlways"
but it doesn't have any scroll flags - is it a bug or am I doing something wrong? I want it to be always visible
before scroll
after scroll
Update
opened a google issue on this - it was marked 'WorkingAsIntended' this still doesn't help because I want a working solution of a footer inside a fragment.
Update 2
you can find the activity and the fragment xmls here -
note that if line 34 in activity.xml
- the line containing app:layout_behavior="@string/appbar_scrolling_view_behavior"
is commented out the text end is visible from the start - otherwise, it is visible only after scrolling up
I think creating a fixed header and footer could solver your problem. I would've wrote this in the comments but I don't have 50 rep. You could figure out how to do it here
There is a library for your problem. Hope this will really help for you Here is the library
And another problem you have mentioned fixed the footer. the below one is the relative layout so use the feature
android:layout_alignParentBottom="true"
on your footer.Hope you i have solved the issue
This behavior basically removes scroll flag
SCROLL
fromAppBarLayout
, when scrolling content in dependent view (RecyclerView
,NestedScrollView
) is less than view height, ie. when scrolling is not needed. It also overrides offsetting scrolling view, which is normally done byAppBarLayout.ScrollingViewBehavior
. Works well when adding footer, ie. button, to scrolling view or inViewPager
, where content length may be different in each page.Update
The solution below doesn't work for 5.1 as it works in 5 - instead of getTop use getTranslationY in any of the calculations you do.
Update 2 with the new support library - 22.2.1 - there is no diff between 5.1 and prev versions, you should only use getTop and ignore the previous update in this answer
Original solution After looking into many directions turns out the solution is actually simple - add paddingBottom to the fragment and adjust it as the page scrolls.
The padding is needed to cover for the changes in the toolbar y position - the coordinator layout is moving the entire page up and down as the toolbar disappears and reappears.
This can be achieved by extending
AppBarLayout.ScrollingViewBehavior
and setting this as the behavior of the fragment element of the activity.Here are the basics of the code - it works for an activity with only a toolbar - you can replace it with
appbar.getTop() + toolbar.getHeight()
and this will work better if your appbar includes tabs.activity.xml
fragment.xml
MainActivityFragment#onActivityCreated
MyBehavior
Android CoordinatorLayout Bottom Layout Behaviour Example
activity_bottom.xml
FooterBarLayout.java
FooterBarBehavior.java
I did something along the lines of ensuring I added
android:layout_gravity="end|bottom"
to the layout in XML that I wanted at the bottom of theCoordinatorLayout
and then set in code:
Note: that the footer View/ViewGroup needs to be higher in the z-axis (listed below the RecyclerView in XML) to function properly