Bart Bergmans
Bart Bergmans

Reputation: 4121

RecyclerView below LinearLayout in ScrollView

For my app I have to show a list of data (100 items) in a fragment and there has to be some text and an image above it. This all has to be in a single ScrollView so you can scroll in the whole page and not just in the list of data.

When I don't use the ScrollView it's only possible to scroll in the RecyclerView but the user needs to scroll over the complete page.

  Scrollview
|------------|
|            |
|    text    |  <-- LinearLayout
|            |
|------------|
|            |
|    list    |  <-- RecyclerView, longer than screen height
|            |
|------------|

So how can I make it this way without making giving the list the height of all the items combined. This won't be an option because I need to load data from an API that paginates the results (15 results per API call)

Upvotes: 2

Views: 2586

Answers (2)

Ravi Theja
Ravi Theja

Reputation: 3401

Use CoordinatorLayout and Recyclerview to achieve this. Or you can add the top view as header to RecyclerView instead of using recyclerview in ScrollView which does not work as intended until you fix the height of the RecyclerView

UPDATE :

Please follow this link for sample implementations using design library.

Upvotes: 2

Dmitri Timofti
Dmitri Timofti

Reputation: 2418

You might want use the LinearLayout with the text and image as a header view inside the RecyclerView and drop the ScrollView.

This post explains how to create a header view in a RecyclerView: https://stackoverflow.com/a/26573338/4605725

Upvotes: 1

Related Questions