androidandroid-recyclerview

RecyclerView that does not scroll and shows all items


I have a RecyclerView (and some other views) in a ScrollView. Currently the RecyclerView is laid out as very small (it shows 2 items out of 5 that it contains) and it scrolls independently of the ScrollView, which is obviously not great UX. I would like to get the RecyclerView to not scroll and to extend so that all its items are visible.

(I know it's stupid to use a RecyclerView in this case. I'm only doing this because somewhere else in the app I need a normal RecyclerView with scrolling etc. but the same kind of content, and I don't want to duplicate code).


Solution

  • It’s pretty simple, simply set the RecyclerView’s height to wrap_content.

    You might also benefit from disabling nested scrolling on the recycler view, like so:

    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setNestedScrollingEnabled(false);