Reputation: 3108
I have a RecyclerView
with height:match_parent which displays 16 items vertically with fixed height in adapter. Everything works fine except when it comes to the different screen sizes. In larger screens there is a space remained at the bottom after 16 items are displayed, where on small screen phones it perfectly fits to the bottom. I am looking for a way where list items heights are adjusted to the RecyclerView
height till the end without scrollable.
Check the Screenshots below for more clarification
Problem:
Expectation:
My approach was to make the Item weight set to 1, hence when rendering into the RecyclerView
16 times, they will share the same height within the RecyclerView
. Unfortunately that didn't work for me.
My RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_morning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
My Adapter:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:clickable="false"
android:orientation="vertical">
<TextView />
</LinearLayout>
Upvotes: 9
Views: 3986
Reputation: 1240
The exact solution for your problem is the flexible layout manager for ReyclerView.
An example illustrating the use of flexible layouts.
Upvotes: 2