RecyclerView items with big empty space after 23.2.0

前端 未结 5 590
后悔当初
后悔当初 2020-11-30 01:54

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 simp

相关标签:
5条回答
  • 2020-11-30 02:21

    You must make Recyclerview and item layout heights wrap content.

    0 讨论(0)
  • 2020-11-30 02:24

    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>
    

    0 讨论(0)
  • 2020-11-30 02:25

    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.

    0 讨论(0)
  • 2020-11-30 02:28

    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);
    
    0 讨论(0)
  • 2020-11-30 02:32

    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" 
    
    0 讨论(0)
提交回复
热议问题