【问题标题】:Each Recyclerview item is shown in a whole page [duplicate]每个 Recyclerview 项目都显示在整个页面中[重复]
【发布时间】:2019-01-15 07:47:38
【问题描述】:

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

【问题讨论】:

    标签: android recyclerview-layout


    【解决方案1】:

    您已将项目的宽度和高度设置为 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" />
    

    【讨论】:

    • 非常感谢。我的问题已经解决了。
    【解决方案2】:

    在您的RelativeLayout 中设置android:layout_height= "wrap_content"

    【讨论】:

    • 非常感谢。我的问题已经解决了。
    【解决方案3】:

    看看你在做什么基本上你正在分配 layout_height = match_parent 这意味着你的每个项目都会尝试占据全屏空间,而不是你要做的是你可以通过提供静态值来修复项目的高度喜欢

    android:layout_height="200dp"
    

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

    android:layout_height="wrap_content"
    

    希望您了解问题并获得可能的解决方案。

    【讨论】:

    • 非常感谢。我的问题已经解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多