首页 > 解决方案 > 每个 Recyclerview 项目都显示在整个页面中

问题描述

这是我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" />

标签: androidrecyclerview-layout

解决方案


您已将项目的宽度和高度设置为 match_parent,这使您的项目比您想要的更大。像这样使用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" />

推荐阅读