3

I have a simple ImageView of a trashcan which I imported as a vector asset. This is the 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" />

Why is it that the shadow does not show even with elevation? I would like to avoid using a cardview container and use its shadow because otherwise I would have to enclose any kind of ImageView in a cardView just for that reason.

The above ImageView's parent is a ConstraintLayout.

bcsta
  • 1,963
  • 3
  • 22
  • 61

1 Answers1

3

Adding android:outlineProvider="paddedBounds" showed the elevation shadow. Does anyone know why?

bcsta
  • 1,963
  • 3
  • 22
  • 61
  • If there is no background, there is nothing for Android to use to cast the shadow. `paddedBounds` uses the "padded bounds", which is essentially the square space the view takes up, less the padding of the view. it also cause the background to not be used when casting a shadow. In the case of a vector background, since that is apparently not support (or broken), using `paddedBounds` will ignore that background and switch to one that it can work with. – methodsignature Sep 02 '21 at 10:23