Android RecyclerView项填充整个屏幕

Android RecyclerView项填充整个屏幕,android,android-recyclerview,android-7.0-nougat,Android,Android Recyclerview,Android 7.0 Nougat,我有一个Recyclerview,它在Android版本23上运行良好,但是如果我在Android版本25上运行相同的代码,那么整个屏幕都被单个项目占据 最初,当项目高度为包裹内容时,列表看起来很好。但当我滚动时,整个屏幕被单个项目占据 以下是我包含RecyclerView的布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="matc

我有一个Recyclerview,它在Android版本23上运行良好,但是如果我在Android版本25上运行相同的代码,那么整个屏幕都被单个项目占据

最初,当项目高度为包裹内容时,列表看起来很好。但当我滚动时,整个屏幕被单个项目占据

以下是我包含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>


请使用recyclerview项目的主布局高度“包裹内容”。

您的recyclerview代码正常。 如果您在iteam_raw.xml中使用TextView或其他格式,请确保 “包装内容”

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>

确保您在ViewHolder中使用的所有UI元素必须具有包裹内容的高度,如果您将cardview用作父容器,则还应确保该高度包裹内容。

将布局高度属性从匹配元素更改为包裹内容或其他
change the layout_height property from match_element to wrap_content or some 
size  in your linearlayout.

example:
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="120dp" <-- **change in height**
android:layout_width="match_parent"
android:orientation="vertical">
在你的线性布局中的尺寸。 例子:
请发布您的recyclerview项目xml。发布您在recyclerview中膨胀的项目布局。只有我们才能更准确地帮助您。为您膨胀的版面高度设置包裹内容。