Joaquin Iurchuk
Joaquin Iurchuk

Reputation: 5617

Recycler View as part of a Scroll View

I'm developing an app that has an UI pretty similar to Play Store. It is organized as a multiple panels one above another. First it has a panel containing a photo. Under that it has another panel containing some text and a custom background color. Under that it has another photo and finally it has a Linear Layout with vertical orientation containing a pretty long list of little views filled dynamically at runtime. I have all this inside a Scroll View, naturally.

The problem? That dynamic fill of the linear layout takes a long processor time and makes my app unresponsive during those inner views inflation. So I thought to replace the linear layout by a Recycler View. And the performance is awesome!

So? Well... Not everything is so awesome. I can't scroll the Recycler View because it's inside the Scroll View. And if I remove the Scroll View then I can't scroll the entire view (some things doesn't fit on the screen).

What's the best approach for fixing this?

Upvotes: 1

Views: 537

Answers (2)

Shubham Rai
Shubham Rai

Reputation: 71

Just use a NestedScrollView instead of a normal ScrollView. It handles the nested scrolling quite well.

Upvotes: 0

Michael Garner
Michael Garner

Reputation: 1092

It's not recommended to use a RecyclerView or ListView inside of a ScrollView precisely due to the double scrolling issues. RecyclerView is very robust and is prepared to receive headers, footers, etc. I see no reason why the entire layout could not be inside of a RecyclerView instead of a ScrollView

The ViewHolder implementation can include logic to inflate different layouts depending on what section should be next.

Pseudocode:

i.e.

if(currentAdapterItem == sectionA){
    useLayoutA();
} else{
    useLayoutB();
}

Upvotes: 3

Related Questions