Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 每个Recyclerview项目显示在整个页面中_Android_Recyclerview Layout - Fatal编程技术网

Android 每个Recyclerview项目显示在整个页面中

Android 每个Recyclerview项目显示在整个页面中,android,recyclerview-layout,Android,Recyclerview Layout,这是我的XML代码,用于RecyclerView项目。问题是,每个项目都显示在整个应用程序页面中。请帮我解决这个问题: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/rootlayout" android:layout_

这是我的
XML
代码,用于
RecyclerView
项目。问题是,每个项目都显示在整个应用程序页面中。请帮我解决这个问题:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rootlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="8dp"
    android:background="@color/black"
    android:gravity="center">


  <com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/iv_wall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp" />

  <View
    android:id="@+id/view_wall"
    android:layout_width="160dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradient_black_round"
    android:gravity="center_vertical" />


您已将物品的宽度和高度设置为与父项匹配,这使您的物品比您想要的更大。像这样使用smth:

      <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootlayout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="8dp"
android:background="@color/black"
android:gravity="center">


<com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/iv_wall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp" />

<View
    android:id="@+id/view_wall"
    android:layout_width="160dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradient_black_round"
    android:gravity="center_vertical" />

您已将物品的宽度和高度设置为与父项匹配,这使您的物品比您想要的更大。像这样使用smth:

      <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootlayout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="8dp"
android:background="@color/black"
android:gravity="center">


<com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/iv_wall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp" />

<View
    android:id="@+id/view_wall"
    android:layout_width="160dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradient_black_round"
    android:gravity="center_vertical" />


set
android:layout\u height=
在您的
RelativeLayout
set
android:layout\u height=
在您的
RelativeLayout
中查看您正在做的事情基本上您正在分配布局\u高度=
匹配\u父项
,这意味着您的每个项目将尝试占据全屏空间,而您需要做的是,您可以通过提供静态值来固定项目的高度,如

android:layout_height="200dp"
另一种方法是让您的视图通过使用(推荐方式)来决定它需要多少空间


希望您理解问题并找到可能的解决方案。

看看您在做什么基本上您是在分配布局_height=
匹配_parent
,这意味着您的每个项目都将尝试占据全屏空间,而您需要做的是,您可以通过提供静态值来固定项目的高度,如

android:layout_height="200dp"
另一种方法是让您的视图通过使用(推荐方式)来决定它需要多少空间


希望您了解问题并找到可能的解决方案。

非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了。