Rahim Rahimov
Rahim Rahimov

Reputation: 1417

How to add elevation to transparent ImageView [android]

Is it really to implement elevation of ImageView with png that contains transparent background? For example: i want to add elevation shadow to this pic:

enter image description here

Want make it like this:

enter image description here

Upvotes: 11

Views: 6692

Answers (1)

Chris Stillwell
Chris Stillwell

Reputation: 10547

In your XML add this:

android:elevation="2dp"    
android:background="@drawable/myrect"

In your Drawable folder add this drawable:

<!-- res/drawable/myrect.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="#42000000" />
    <corners android:radius="5dp" />
</shape>

See here for more info: http://developer.android.com/training/material/shadows-clipping.html

Upvotes: 1

Related Questions