Input data:
- LinearLayout with a couple of views (further "Info")
- RecyclerView with pagination
In theory, the objective is easy: make both views scrollable like a single container. In practice, it is ridiculously complicated.
Attempt #1: NestedScrollView
Before I integrated the Paging library, both the Info and the Recycler were inside of a NestedScrollView and it worked as I wanted, except for the performance (sometimes there are ~500 items, and the UI freezes for ~4 seconds). Now, since RecyclerView is inside the NestedScrollView, my paging doesn't work: it loads all the data at once! I decided to find another way.
Attempt #2: CoordinatorLayout
I found this answer to be a possible solution. And it works perfectly with highly populated RecyclerView. However, when the list is empty, I can scroll all the way down to the blank screen and I won't be able to scroll back up. If I have a few items, I can also scroll halfway to the blank screen. Only a high amount of data works well with this approach. I understand that behavior because I have a scroll flag "exitUntilCollapsed" but is there a workaround for this?
Is there any solution to this problem? Such a simple task requires tons of workarounds (and workarounds for workarounds) to have the info and the recycler to be scrollable as a single container.
CodePudding user response:
there is another solution to solve this problem, use multiple view type to make the linearlayout as a part of recyclerview items. check this answer out.
CodePudding user response:
The main idea is to put inside your adapter realization different viewHolder's
and switching between them by different item types (needs to override getItemViewType
). Here is an article about it, check out: medium