【问题标题】:Excessive padding between Cardviews in RecyclerView?RecyclerView中Cardviews之间的填充过多?
【发布时间】:2016-09-13 01:01:50
【问题描述】:

我很难减少 RecyclerView 中卡片之间的填充

Padding Issue Screenshots

上面的屏幕截图是在开发者模式的“显示布局边界”选项中截取的,所以问题似乎与填充有关。

当 CardView 被移除时,它会恢复到正常的填充,虽然我不会做这个改变,因为我想要 CardView

我手动添加了无效的负填充和零填充。

我还添加了card_view:cardUseCompatPadding="true",但也没有用。

我的代码:

<?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"
    android:layout_marginTop="20dp">

    <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="fill_parent"
        android:layout_height="225dp"
        android:layout_margin="10dp"
        android:clickable="true"
        android:elevation="2dp"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardCornerRadius="2dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardUseCompatPadding="true"
       >

       <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="-25dp"
            android:orientation="horizontal"

            >

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="200dp"
                android:layout_height="match_parent"
                android:layout_alignLeft="@+id/card_view"
                android:layout_gravity="left|center_vertical"
                android:scaleType="fitCenter" />

            <TextView
                android:id="@+id/Ayoub"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="fill_vertical|fill_horizontal"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"

                />

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

【问题讨论】:

  • 尝试更改图像视图的比例类型

标签: android android-layout android-studio android-recyclerview android-cardview


【解决方案1】:

改变这个:

android:layout_height="225dp"

到:

android:layout_height="wrap_content"

【讨论】:

    【解决方案2】:

    你的第一个 RelativeLayout 应该 wrap_content 不匹配_parent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 2019-09-28
      • 2015-02-12
      相关资源
      最近更新 更多