How to add elevation to transparent ImageView [android]
Asked Answered
M

1

11

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

Maible answered 22/10, 2015 at 15:16 Comment(2)
Did you solve this?Naive
@AyushSth Just added it as a png with a shadow as shown above... That was 2015.. Maybe now it can be solved correct way but not sure.Maible
P
1

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

Purine answered 22/10, 2015 at 15:19 Comment(5)
i know that. but it will add only rectangle shadow around the View. I want to add shadow only around NON transparent pixels in my ImageView.Maible
Change the radius to match your object's radiusPurine
it makes only rectangle or full circle shadows.Maible
how can i draw this shape in drawable?Maible
See this answer for half circle drawables: #15963245Purine

© 2022 - 2024 — McMap. All rights reserved.