Elevation not working for ImageView

Karthik picture Karthik · Jun 4, 2015 · Viewed 29.7k times · Source

Elevation for ImageView is not working. I declared ImageView in XML like this:

<ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:elevation="10dp"
        android:src="@drawable/youtube" />

What else should I do for elevation to work properly for ImageView?

Answer

BladeCoder picture BladeCoder · Jun 4, 2015

The elevation shadow is derived from the background drawable of a View. If your ImageView has no background, you'll see no shadow.

If you want to change that behavior, you need to build your own ViewOutlineProvider and call View.setOutlineProvider() to set it (and this is not trivial).