首页 > 解决方案 > 背景卡片视图形状未定义

问题描述

我定义了一个类似于下图的 CardView,但它后面还有一个尚未定义的形状(红色箭头)。我知道 CardView 是造成问题的原因,因为如果你用 LinearLayout 替换它就没有问题。使用 Layout Inspector 我也看不到这个形状,有谁知道它是否是导致不需要的形状出现的 cardView 的规范?

卡片视图图像

<androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@color/Transparent"
        app:cardPreventCornerOverlap="false"
        app:cardCornerRadius="16dp"
        app:cardElevation="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

更新: 将高程值设置为较高的值,例如 128dp,不会出现问题。这不是理想的解决方案,但它解决了

标签: androidandroid-cardview

解决方案


您可以按形状创建这个圆角背景。例子:

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:tint="@color/base_color">

    <corners android:radius="@dimen/corners_radius" />
</shape>

我不是 100% 肯定,但我认为它是由海拔高度引起的。


推荐阅读