【问题标题】:Remove extra spaces between CardViews in RecyclerView [duplicate]删除 RecyclerView 中 CardViews 之间的额外空格 [重复]
【发布时间】:2016-02-04 09:07:44
【问题描述】:

我在RecyclerView 中有几个CardView,我无法删除它们之间的多余空格。

我的CardView

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="0dp"
    card_view:cardBackgroundColor="@color/white"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="0dp"
    card_view:cardUseCompatPadding="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:background="@drawable/rounded_corner"
        android:paddingBottom="8dp">

        <TextView
            android:id="@+id/textViewName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_toRightOf="@+id/imageView"
            android:text="HEAD"
            android:textColor="@color/black"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/textViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textViewName"
            android:layout_below="@+id/textViewName"
            android:layout_marginRight="8dp"
            android:layout_marginTop="4dp"
            android:text="SUBHEAD"
            android:textColor="@color/black"
            android:textSize="14sp" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_alignParentEnd="false"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="false"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp" />

    </RelativeLayout>

</android.support.v7.widget.CardView>

我的RecyclerView

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview_user_data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    android:background="@color/grey_bg" />

Screenshot。红色箭头指向额外的空间。

【问题讨论】:

  • 请显示回收站查看代码。
  • android:paddingBottom="8dp" 尝试从您的相对布局中删除它..
  • @ShoebSiddique,抱歉回复晚了。我已经添加了RecyclerView xml 代码。
  • @HourGlass,还有多余的空格。

标签: android xml android-recyclerview android-cardview


【解决方案1】:

如果你想一起摆脱它,你可以对 CardView 的 contentPadding 属性使用否定,例如:

card_view:contentPadding="-8dp"

添加负边距应该可以。

【讨论】:

  • 谢谢,我已经删除了空格,但我听说这是“丑陋”的解决方案。
  • 是的,但没有其他选项可用于此@MrAwesome
  • 它减少了卡片大小而不是它们的空格
猜你喜欢
  • 1970-01-01
  • 2013-01-09
  • 2020-10-16
  • 2014-06-22
  • 1970-01-01
  • 2016-03-13
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多