2016-03-01 30 views
33

Sau khi cập nhật lên v23.2.0 trong số RecyclerView Tôi có các mục có khoảng trống dọc lớn, giữa các mục.RecyclerXem các mục có khoảng trống lớn sau 23.2.0

bố cục mục của tôi rất đơn giản:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"          
     android:orientation="vertical" > 
+0

Vẫn còn lỗi này tồn tại trong 23.4.0 nơi tôi có lồng nhauScrollView {recyclerview. các mục()} khi tôi loại bỏ vài mục trong số đó có nghĩa là sắp xếp sẽ để trống không gian trống .... –

+0

Đó không phải là lỗi, hành vi mong đợi hiện nay. Các câu hỏi liên quan [ở đây] (http://stackoverflow.com/q/35677694/1009132), [tại đây] (http://stackoverflow.com/q/35747268/1009132) và [tại đây] (http: // stackoverflow. com/q/37504796/1009132) – albodelu

Trả lời

106

Theo doc

Với việc phát hành 23.2.0 có một tính năng mới thú vị để các API LayoutManager: auto đo lường!
Điều này cho phép một số RecyclerView tự kích thước dựa trên kích thước nội dung của nó. Điều này có nghĩa là các kịch bản trước đó không có sẵn, chẳng hạn như sử dụng WRAP_CONTENT cho một kích thước của RecyclerView, hiện có thể.
Bạn sẽ tìm thấy tất cả các Trình quản lý bố cục tích hợp sẵn hỗ trợ đo lường tự động.

Do sự thay đổi này, hãy chắc chắn để kiểm tra các thông số bố trí quan điểm mục của bạn tăng gấp đôi: phớt lờ trước các thông số bố trí (như MATCH_PARENT theo hướng cuộn) sẽ tại hoàn toàn tôn trọng .

Trong bố cục mục của bạn, bạn cần phải thay đổi:

android:layout_height="match_parent" 

với

android:layout_height="wrap_content" 
+2

Tuyệt vời! Tôi không biết đó là gì ... –

+0

@GabrielMorenoIbarra Cảm ơn người đàn ông bạn đã cứu cuộc sống của tôi –

+2

Cảm ơn bạn của tôi đã cứu tôi một buổi tối thất vọng do hành vi trực quan bất ngờ và phản đối. Bravo. –

13

Bạn phải làm Recyclerview và chiều cao bố cục mục quấn nội dung.

3

Điều này phù hợp với tôi.

<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> 

2

Trong trường hợp của tôi, tôi đã thực hiện những thay đổi wrap_content mới nhưng vẫn còn một khoảng cách mà thể hiện trong onMove hoặc onSwipe. Tôi đã giải quyết điều đó bằng cách thêm mã này:

mRecyclerView.getLayoutManager().setMeasurementCacheEnabled(false); 
Các vấn đề liên quan