user924
user924

Reputation: 12145

ImageView elevation: shadow is cropped at the bottom

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?

Upvotes: 2

Views: 1790

Answers (2)

amit lalwani
amit lalwani

Reputation: 11

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"

Upvotes: 0

karan
karan

Reputation: 8853

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"

Upvotes: 1

Related Questions