Android LinearLayout : Add border with shadow around a LinearLayout
Try this..
<?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="#CABBBBBB"/> <corners android:radius="2dp" /> </shape> </item> <item android:left="0dp" android:right="0dp" android:top="0dp" android:bottom="2dp"> <shape android:shape="rectangle"> <solid android:color="@android:color/white"/> <corners android:radius="2dp" /> </shape> </item></layer-list>
That's why CardView exists. CardView | Android Developers
It's just a FrameLayout that supports elevation in pre-lollipop devices.
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" app:cardUseCompatPadding="true" app:cardElevation="4dp" app:cardCornerRadius="3dp" > <!-- put whatever you want --></android.support.v7.widget.CardView>
To use this you need to add dependency to build.gradle
:
compile 'com.android.support:cardview-v7:23.+'
I get the best looking results by using a 9 patch graphic.
You can simply create an individual 9 patch graphic by using the following editor:http://inloop.github.io/shadow4android/
Example:
The 9 patch graphic:
The result:
The source:
<LinearLayoutandroid:layout_width="200dp"android:layout_height="200dp"android:orientation="vertical"android:background="@drawable/my_nine_patch"