I have a RecyclerView
wrapped in a LinearLayout
and it works perfectly as expected. I can see all the data in the RecyclerView
as populated. So far so good.
When I wrap the LinearLayout
in a ScrollView
, the RecyclerView
goes blank. I do not see anything inside RecyclerView
. Why? How to make this work.
The page is one of the tabs in a ViewPagerIndicator
, so everything in that tab needs to be in a ScrollView
.
Thanks for all the help.
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
It's pretty simple, simply set the RecyclerView 's height to wrap_content . That's right.
setnestedscrollingenabled set it to false.
To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .
Set this property for the ScrollView,
android:fillViewport="true"
ScrollView will extend itself to fill the contents
After checking implementation, the reason appears to be the following. If RecyclerView
gets put into a ScrollView
, then during measure step its height is unspecified (because ScrollView
allows any height) and, as a result, gets equal to minimum height (as per implementation) which is apparently zero.
You have couple of options for fixing this:
RecyclerView
ScrollView.fillViewport
to true
RecyclerView
outside of ScrollView
. I my opinion, this is the best option by far. If RecyclerView
height is not limited - which is the case when it's put into ScrollView
- then all Adapter's views have enough place vertically and get created all at once. There is no view recycling anymore which kinda breaks the purpose of RecyclerView
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With