I was wondering if it's possible to create shadow effect for linear layout in android just like shown below. Any help would be appreciated...
Asked
Active
Viewed 3.0k times
1
-
1Is setting `android:elevation` did not work for you? – Much Overflow Jan 25 '16 at 04:21
-
But that is going to work only if the android version is 21 and above. Is there any way that I can add the same design in lower version? – Samuel Robert Jan 25 '16 at 04:31
-
If you really want a shadow effect. you can use a `CardView` with `app:cardUseCompatPadding="true"` May I know the reason why you want to use `LinearLayout` in particular? – Much Overflow Jan 25 '16 at 04:34
-
make `CardView` as parent of `LinearLayout` which you are mentioning. – Vipul Asri Jan 25 '16 at 05:33
-
@SamuelRobert hey have tried it using 9-patch it will be a better solution there are others also i have mentioned those in my answer – Harsh Sharma Jan 25 '16 at 05:34
-
@SamuelRobert see my Updated answer it's work. – Jan 25 '16 at 06:08
2 Answers
6
Then Use 9 Patch image for that,
for more detail here is question for shadow LinearLayout

Community
- 1
- 1
-
I've already tried the above code. Apparently, the above code adds just a border to my Linear Layout. What I really wanted was the blending shadow effect just like I've shown in the image. – Samuel Robert Jan 25 '16 at 05:43
-
-
I appreciate your help. Nonetheless, elevation property would work only if the sdk level is 21 and above. I was trying to accomplish this effect from api level 11 onwards. – Samuel Robert Jan 25 '16 at 06:20
-
-
Buddy, The updated answer just adds a border below the linear layout. What I really need is the fading shadow effect not a border at the bottom. – Samuel Robert Jan 25 '16 at 06:32
-
-
Ya. you got the answer to my question. one more thing though, can we do this just with an xml drawable file?. or 9-patch is the best choice? – Samuel Robert Jan 25 '16 at 06:40
-
you are using api level 11 so it is difficult to make drawable xml of your shape shadow better use 9 patch image for that. – Jan 25 '16 at 06:43
5
There are lots of ways and here they are Use that which one suits you
Create your own drawable
border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="@android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and your_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:background="@drawable/border"
>
</LinearLayout>
You can also use use a drawable from android
android:background="@android:drawable/toast_frame"
or:
android:background="@android:drawable/dialog_frame"
or:
android:background="@android:drawable/dialog_holo_light_frame"
Use a 9-patch image with a shadow and set it as the background to your Linear layout
Use this website to create 9 patch with shadow

Harsh Sharma
- 898
- 1
- 14
- 30
-
Hey, man, how could i smooth more the border shadow color on your code? – Fernando Torres Nov 01 '19 at 01:09