RecyclerView items with big empty space after 23.2.0
Asked Answered
S

5

47

After update to v23.2.0 in my RecyclerView I have items with huge empty vertical space, between the items.

My item layout is very simple:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"                                    
       android:orientation="vertical" >
Subcommittee answered 1/3, 2016 at 16:28 Comment(2)
Still this error persist in 23.4.0 where i have nestedScrollView{ recyclerview . items()} when i remove few of those items meaning a sort would leave empty space sadly....Elnora
It's not an error, the expected behavior now. Related questions here, here and hereDelightful
S
134

According to the doc

With the release 23.2.0 there is an exciting new feature to the LayoutManager API: auto-measurement!
This allows a RecyclerView to size itself based on the size of its contents. This means that previously unavailable scenarios, such as using WRAP_CONTENT for a dimension of the RecyclerView, are now possible.
You’ll find all built in LayoutManagers now support auto-measurement.

Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.

In your item layout you have to change:

android:layout_height="match_parent"

with

android:layout_height="wrap_content" 
Subcommittee answered 1/3, 2016 at 16:28 Comment(2)
My item layout was using a Constraint Layout which was causing some problems as well, switching that to a Linear Layout in accordance with the above answer solved my issueYang
@GabrielMoreno When I change the layout_height to wrap_content in my recyclerView and my imageView , images didn't appearJosselyn
S
15

You must make Recyclerview and item layout heights wrap content.

Siesta answered 6/3, 2016 at 19:26 Comment(1)
When I change the layout_height to wrap_content in my recyclerView and my imageView , images didn't appearJosselyn
I
6

In my case, I had made the new wrap_content changes but there was still a gap that manifested during onMove or onSwipe. I solved that by adding this code:

mRecyclerView.getLayoutManager().setMeasurementCacheEnabled(false);
Illdefined answered 16/9, 2017 at 22:41 Comment(0)
I
3

This is work for me.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:elevation="7dp"
    app:cardCornerRadius="7dp"
    app:cardMaxElevation="7dp"
    app:contentPadding="7dp"
    android:layout_margin="5dp"
    >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv_allfeedbacks_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:textSize="14dp"
        android:textStyle="bold"
        />
    <TextView
        android:id="@+id/tv_allfeedback_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        />
    <TextView
        android:id="@+id/tv_allfeedbacks_comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_allfeedbacks_title"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        />
        <TextView
            android:id="@+id/tv_allfeedbacks_username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="5dp"
            />
        <RatingBar
            android:id="@+id/ratingbar_allfeedbacks"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:numStars="5"
            android:layout_margin="5dp"
            style="?attr/ratingBarStyleSmall"
            />
        </RelativeLayout>

</android.support.v7.widget.CardView>

Integrator answered 13/12, 2016 at 10:48 Comment(0)
A
1

None of the given Solution worked.

Setting layout_height = "wrap_content" did not work either.

Parent layout of my list design is ConstraintLayout and that was the problem(don't know what). But after changing parent layout to RelativeLayout everything work fine.

Airlie answered 21/5, 2020 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.