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" />
setandroid:layout\u height=
在您的RelativeLayout
setandroid:layout\u height=
在您的RelativeLayout
中查看您正在做的事情基本上您正在分配布局\u高度=匹配\u父项
,这意味着您的每个项目将尝试占据全屏空间,而您需要做的是,您可以通过提供静态值来固定项目的高度,如
android:layout_height="200dp"
另一种方法是让您的视图通过使用(推荐方式)来决定它需要多少空间
希望您理解问题并找到可能的解决方案。看看您在做什么基本上您是在分配布局_height=匹配_parent
,这意味着您的每个项目都将尝试占据全屏空间,而您需要做的是,您可以通过提供静态值来固定项目的高度,如
android:layout_height="200dp"
另一种方法是让您的视图通过使用(推荐方式)来决定它需要多少空间
希望您了解问题并找到可能的解决方案。非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了,非常感谢。我的问题已经解决了。