每个 Recyclerview 项目都显示在整个页面中
Each Recyclerview item is shown in a whole page
这是我的 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" />
您已将项目的宽度和高度设置为 match_parent,这使得您的项目比您想要的要大。像这样使用:
<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" />
在你的RelativeLayout
中设置android:layout_height=
"wrap_content"
看看你在做什么基本上你正在分配 layout_height = match_parent
这意味着你的每个项目都会尝试全屏 space 而不是你必须做的是你可以通过提供
之类的静态值来修复项目的高度
android:layout_height="200dp"
另一种方法是使用(推荐方式)
让您的视图决定它需要多少 space
android:layout_height="wrap_content"
希望您了解问题并找到可能的解决方案。
这是我的 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" />
您已将项目的宽度和高度设置为 match_parent,这使得您的项目比您想要的要大。像这样使用:
<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" />
在你的RelativeLayout
android:layout_height=
"wrap_content"
看看你在做什么基本上你正在分配 layout_height = match_parent
这意味着你的每个项目都会尝试全屏 space 而不是你必须做的是你可以通过提供
android:layout_height="200dp"
另一种方法是使用(推荐方式)
让您的视图决定它需要多少 spaceandroid:layout_height="wrap_content"
希望您了解问题并找到可能的解决方案。