Reputation: 533
EDIT
I solved this problem by using CoordinatorLayout
and a AppBarLayout
as a wrapper for the header and TabLayout
. Should have been pretty obvious but oh well.
ORIGINAL QUESTION: I have a design that I have tried multiple iterations to accomplish for my application. I know that nesting scrollable views is not to prefer but i believe is doable, I cant really find the answer I am looking for my specific problem so here goes.
Here is a simple mockup of the design and how I imagine how I would implement it:
This is some kind of profile-design where at the top there is some textviews, banner, avatar and jadajada. Below is three tabs which are used to switch the content below them.
The content for each tabs are of the same kind object, they just have their own "filter"
The implementation below is pretty straight forward at start.
We use a recyclerview
Inside that we have some different viewholders where one of them contains a viewpager.
The viewpager contains of fragments that in them contains another recyclerview.
I have found a lot of problems by doing this way. And haven't really accomplished so that everything feels like one single scrollview.
I have also tried using one single recyclerview for everything but the animation between tabs isn't really what we are looking for, also it was a real inconsistency mess.
I think my real question here is am I putting water over my head, should i approach this a different way? Has anyone else done this in an elegant way?
Upvotes: 1
Views: 1074
Reputation: 353
Some time ago I faced with the same task, and in my mind there is a bad idea to use ViewPager as nested scroll view
The trick is using several RecyclerViews only for whole screen. I prepared a simple example how you could do it
https://github.com/tpec1k/NestedRecyclerViews
example gif (too large for making it inline): https://www.dropbox.com/s/129te4ie87uuyqi/device-2017-08-16-125556.gif?dl=0
PS I know that RecyclerView isn't ViewPager but it could be very similar Look, you just need to add title strips, fix scroll behavior and override change item animation.
PPS I didn't try but looks there are some libs on github that implements viewpager logic in recyclerview: - https://github.com/lsjwzh/RecyclerViewPager
Upvotes: 1