I am using the view CoordinatorLayout
from android.support.design
. I want to attach the app:layout_behavior
to the fragment's RecyclerView
?
In the example given by Google, they only attach it in the RecyclerView
of the same XML file where the CoordinatorLayout
was attached.
Is there a way to attach CoordinatorLayout
to the fragment's RecyclerView
within the ViewPager
?
The sample is in this blog post at Android Developers blog.
I recently had the same problem mentioned in the post, and the above solutions did not work for me. Luckily I managed to solve it. So just to share I am posting here
The problem was that in my code I had set
due to which the appbar was not responding to recyclerView's scrolls despite setting the layout_behaviour attribute to the viewPager. Changing the above-mentioned attribute to
solved the problem and the appbar started responding to the recylerView's scroll.
Use a FrameLayout and inject your fragment into that FrameLayout. Then set app:layout_behavior to it. The only thing you need to do is set layout_behavior to a sibling of AppBayLayout and that sibling will below the toolbar.
After a few tests, I found that put the TabLayout outside AppBarLayout, will works, whatever the viewpager's Fragment contains. This is my main xml.
I'm having the same problem, i solved the scrolling but putting toolbar and the tabs inside the app bar and wrap it and the viewpager with a coordinatorlayout. Also in the layout of my recycle view(to be inflated) i add the layout_behavior. It works but the problem is everything is over each other.
This is my main page
and this is my layout for the adapter
If I get it to work better ill tell you.
Chris Banes has posted a sample on Github which shows exactly what you want to do.
Here is the xml file that defines how one can indirectly attach a coordinator layout to the viewpager's fragments.
The idea is to let the viewpager have the layout_behavior attribute.
This might be dumb, but it didn't worked due to the fact that the build tool was not updated in the
build.gradle
of the application version to 22, I was using 21 that is why it is not working as expected to be.Edit:
Also what SanderTuit said: adding
com.android.support:recyclerview-v7:22.2.0
will also solve the problem