【问题标题】:Extra padding at top and bottom in CardViewCardView 顶部和底部的额外填充
【发布时间】:2017-08-21 06:38:50
【问题描述】:

我正在使用 recyclerview 来显示来自网络服务的图像列表。我正在尝试在 CardView 小部件中的 ImageView 中显示图像。一切正常。所有图像和列表都正确显示。但是当我尝试在 Kitkat 4.4.4 上运行时,它会在 Cardview 中图像的顶部和底部显示额外的(大)填充。我只使用 ImageView,没有任何文字。

检查附件。

在 4.4.4 上

在棒棒糖上 到目前为止,我已经尝试了几乎所有我在 SO 上找到的东西。 任何帮助表示赞赏。 谢谢

Cardview 的 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half">

<android.support.v7.widget.CardView
    android:layout_centerHorizontal="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/offwhite"
    android:id="@+id/cardlayout_malls"
    android:layout_marginLeft="@dimen/activity_horizontal_margin_half"
    card_view:cardUseCompatPadding="true"
    android:layout_marginRight="@dimen/activity_horizontal_margin_half">-->
    <!-- Thumbnail Image -->

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bannerImageView"/>
    </android.support.v7.widget.CardView>
    </RelativeLayout>

【问题讨论】:

  • 显示你的 xml 文件
  • 您是否在适配器的 XML 文件中使用 match_parent,如果是,则将其更改为 wrap_content
  • 请张贴xml代码
  • @RakshitNawani 我使用 wrap_content 作为高度,使用 match_parent 作为宽度
  • @deejay : 请分享您的 XML 代码以便更好地理解

标签: android android-layout android-imageview padding android-cardview


【解决方案1】:

试试这个方法

card_view:cardPreventCornerOverlap="false"

在 imageview 中,您可以使用将其添加到 imageview 中

 <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:id="@+id/bannerImageView"/>

【讨论】:

  • no resources found for adjustedviewbound.. 你能说得更具体点吗?
  • @deejay 立即查看
  • 感谢@Aditya 它的工作.. 现在它没有显示任何填充但高程和阴影效果也消失了.. 你能在这里指导我吗?
  • 我知道使用&lt;view/&gt; 在卡片视图下制作阴影,但这似乎不是一个简洁的方法。
【解决方案2】:

添加card_view:cardPreventCornerOverlap="false" 额外的填充是因为那些需要禁用的小圆角。基本上这不是缺陷,而是设计约束!

【讨论】:

  • 试过了......它在 5.0 及更高版本上去除圆角,但在 4.4.4 上仍然相同