【问题标题】:android:elevation is not working on an imageView of a vector drawableandroid:elevation 不适用于矢量可绘制对象的 imageView
【发布时间】:2019-12-18 07:37:30
【问题描述】:

我有一个简单的ImageView 垃圾桶,我将它作为矢量资产导入。这是 XML

<ImageView
    android:id="@+id/trashcan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="10dp"
    android:layout_marginBottom="8dp"
    android:elevation="10dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/ABtn"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/ic_trashcan" />

为什么即使有高度阴影也不显示?我想避免使用cardview 容器并使用它的影子,否则我将不得不将任何类型的ImageView 包含在cardView 中。

上面的ImageView's 父级是ConstraintLayout

【问题讨论】:

  • 它正在工作。我使用了相同的代码。

标签: android imageview android-elevation


【解决方案1】:

添加android:outlineProvider="paddedBounds" 显示高程阴影。有谁知道为什么?

【讨论】:

  • 如果没有背景,Android 就没有任何东西可以用来投射阴影。 paddedBounds 使用“填充边界”,它本质上是视图占用的正方形空间,减去视图的填充。它还会导致在投射阴影时不使用背景。在矢量背景的情况下,由于显然不支持(或损坏),使用 paddedBounds 将忽略该背景并切换到它可以使用的背景。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-23
  • 2014-10-23
  • 2018-10-31
  • 1970-01-01
  • 2018-09-07
相关资源
最近更新 更多