2

I want to add shadow around ImageView

I tried elevation

<ImageView
    android:layout_margin="10dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:src="@drawable/ic_icon_compass"
    android:elevation="2dp"
    android:background="@drawable/ic_circle_white"
    android:padding="10dp"
    android:layout_width="40dp"
    android:layout_height="40dp"/>

Layout Preview works fine

enter image description here

But on the device it looks like this

enter image description here

(shadow is cropped at the bottom)

Why does it happen?

user924
  • 8,146
  • 7
  • 57
  • 139

2 Answers2

1

It looks like parent view is clipping the shadow. Look for the parent that is clipping the shadow it might not be the immidiate parent. Add this to the parent view/s in the xml and check.

android:clipChildren="false"
karan
  • 8,637
  • 3
  • 41
  • 78
0

instead of deciding the height and width in the xml , try to mention in the drawable and instead of using

android:src="@drawable/ic_icon_compass"

use

android:background="@drawable/ic_icon_compass"