2017-02-24 100 views
1

我有一個Recyclerview這是工作的罰款與Android版本23,但如果我對Android版本25那麼整個畫面由單個項目佔據運行相同的代碼。RecyclerView項目填滿整個屏幕

最初,列表看起來很好,其中項目高度是包裝內容。但是,當我滾動整個屏幕被單個項目佔用。

下面是含有RecyclerView我的佈局:

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

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/my_recycler_view" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:scrollbars="vertical" /> 

</LinearLayout> 
+2

請發佈您的recyclerview項目xml。 –

+0

在回收站查看您正在充氣的發佈項目佈局。那麼只有我們能夠更精確地幫助你。 –

+0

爲您的充氣佈局高度設置wrap_content。 –

回答

2

請使用recyclerview項目主要佈局高度 「WRAP_CONTENT」。

1

您的Recyclerview代碼沒問題。 如果您正在使用的TextView或者在您的iteam_raw.xml然後確保你給 「WRAP_CONTENT」

iteam_raw.xml

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

    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

</LinearLayout> 
1

確保您使用的是ViewHolder的所有UI元素都必須有高度來包裝內容,如果你使用cardview作爲父容器,那麼高度也是wrap_content。