【问题标题】:Background cardView shape not defined背景卡片视图形状未定义
【发布时间】:2021-01-14 17:23:45
【问题描述】:

我定义了一个 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,不会出现问题。这不是理想的解决方案,但它解决了

【问题讨论】:

  • 请提供完整的布局代码。

标签: android android-cardview


【解决方案1】:

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

    <?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% 确定,但我认为这是由海拔高度引起的。

【讨论】:

  • 并设置为背景,对吗?像这样 android:background="@drawable/name"
  • 你是对的。无论如何,如果它的高度问题,您可以尝试将其移除或更改阴影颜色。
猜你喜欢
  • 1970-01-01
  • 2020-11-21
  • 2020-09-24
  • 2020-11-16
  • 2022-01-04
  • 1970-01-01
  • 2018-11-18
  • 2011-03-24
  • 1970-01-01
相关资源
最近更新 更多