0

I'm wanting to add a RecyclerView into a ScrollView so I can easily add a header to the RecyclerView.

I've called setAutoMeasureEnabled(true) (part of the recently announced changes to the RecyclerView) to the LayoutManager but the result is no recycling of child views.

If there are 10,000 items in my adapter, 10,000 views are created...

Is this expected behaviour?

Ljdawson
  • 12,091
  • 11
  • 45
  • 60
  • Nesting scrolling views is always problematic. Maybe try one of those solutions: http://stackoverflow.com/questions/26530685/is-there-an-addheaderview-equivalent-for-recyclerview – David Medenjak Mar 10 '16 at 17:53
  • 1
    @DavidMedenjak - I think that is why `NestedScrollView` was created. – OneCricketeer Mar 10 '16 at 17:54
  • @DavidMedenjak adding a header using the adapter is one way for sure but with the addition of the *setAutoMeasureEnabled* method I was curious to see if a ScrollView could be used to simplify this. – Ljdawson Mar 10 '16 at 17:56
  • @cricket_007 I did not say this wasn't possible, I'm just trying to avoid a possible XY problem – David Medenjak Mar 10 '16 at 17:57

2 Answers2

0

I asked on a related Android issue and this is not how this should be used:

https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=74772

For any readers the advise is to NOT used a RecyclerView within a ScrollView with setAutoMeasureEnabled(true).

Ljdawson
  • 12,091
  • 11
  • 45
  • 60
-1

Yes, 10.000 items will be 10.000 view created, to prevent this will need a Paging solution and a Endless RecyclerView

Some references: https://gist.github.com/ssinss/e06f12ef66c51252563e

https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView

Paulo Rodrigues
  • 723
  • 1
  • 5
  • 16