Well, this is easy to achieve .
Just build a GradientDrawable
that comes from black and goes to a transparent color, than use parent relationship to place your shape close to the View that you want to have a shadow, then you just have to give any values to height or width .
Here is an example, this file have to be created inside res/drawable
, I name it as shadow.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#9444"
android:endColor="#0000"
android:type="linear"
android:angle="90"> <!-- Change this value to have the correct shadow angle, must be multiple from 45 -->
</gradient>
</shape>
Place the following code above from a LinearLayout
, for example, set the android:layout_width
and android:layout_height
to fill_parent
and 2.3dp
, you'll have a nice shadow effect on your LinearLayout
.
<View
android:id="@+id/shadow"
android:layout_width="fill_parent"
android:layout_height="2.3dp"
android:layout_above="@+id/id_from_your_LinearLayout"
android:background="@drawable/shadow">
</View>
Note 1: If you increase android:layout_height
more shadow will be shown .
Note 2: Use android:layout_above="@+id/id_from_your_LinearLayout"
attribute if you are placing this code inside a RelativeLayout, otherwise ignore it.
Hope it help someone.