You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CardView内嵌ImageView无法完全填满控件问题求助

问题修复方案

你的布局存在3个直接导致ImageView无法填满CardView的问题,按照以下步骤修改即可解决:

  • 移除ImageView的android:layout_marginStart="10dp"属性,该属性强制在ImageView左侧留出10dp空白,是最直接的留白原因
  • 将ImageView的layout_width、layout_height都修改为match_parent,不要硬编码大于父容器的宽度值,避免测量适配异常
  • 给CardView添加app:cardPreventCornerOverlap="false"属性,关闭CardView默认的内容圆角避让逻辑,避免系统自动给内部子View添加内边距

修改后的CardView区段代码参考:

<androidx.cardview.widget.CardView
    android:layout_width="180dp"
    android:layout_height="130dp"
    app:cardCornerRadius="16dp"
    app:strokeColor="@color/white"
    app:cardPreventCornerOverlap="false">

    <ImageView
        android:id="@+id/iv_news"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/card_background_shape"
        android:scaleType="centerCrop" />
</androidx.cardview.widget.CardView>

额外检查项:如果修改后仍有留白,检查@drawable/card_background_shape文件是否自带padding属性,删除即可。

内容的提问来源于stack exchange,提问作者dazai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 21:09:04