Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 1000
Rahim Rahimov Avatar asked Oct 22 '15 15:10

Rahim Rahimov


People also ask

How to add elevation to view in Android?

To set the default (resting) elevation of a view, use the android:elevation attribute in the XML layout. To set the elevation of a view in the code of an activity, use the View. setElevation() method. To set the translation of a view, use the View.

What is Android elevation?

Elevation (Android) Elevation is the relative depth, or distance, between two surfaces along the z-axis. Specifications: Elevation is measured in the same units as the x and y axes, typically in density-independent pixels (dp).

How do I change the elevation color in react native?

In addition, box shadows in React Native are also not supported on Android, based on this. Save this answer. Show activity on this post. As per @rclai Answer, You cannot change the Elevation color in Android.


1 Answers

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

like image 74
Chris Stillwell Avatar answered Oct 10 '22 16:10

Chris Stillwell