【问题标题】:RecyclerView Items have huge spaces between themRecyclerView 项目之间有巨大的空间
【发布时间】:2016-05-16 06:56:45
【问题描述】:

我有一个包含多个项目的 RecyclerView。而不是项目直接在彼此下方,每行之间的空间最少,每个项目之间有一个巨大的差距,如图所示:(对不起,图像不是很好,我用一个小手机拍的)

Image displaying the issue

我的 RecyclerView 布局文件在这里:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/layout_list_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:textStyle="bold"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/layout_list_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/layout_list_name"
    android:layout_alignLeft="@+id/layout_list_name"
    android:layout_below="@+id/layout_list_name" />

<ImageButton
    android:id="@+id/layout_list_delete"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:contentDescription="@string/layout_list_delete"
    android:src="@drawable/delete" />

我该如何摆脱这个巨大的差距?

【问题讨论】:

  • 请查看更新后的答案
  • 发布包含回收视图的 xml
  • @jankigadhiya 有效吗?

标签: android-studio android-recyclerview


【解决方案1】:

尝试将layout_height="match_parent" 更改为layout_height="wrap_content"。这有望解决您的问题。

【讨论】:

    【解决方案2】:

    将父布局的高度更改为wrap_content。对于您发布的 XML 文件,它应该是:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      相关资源
      最近更新 更多