Search code examples
androidxmlandroid-layoutdrawableshadow

Getting the Facebook Shadow Effect on Background Layout Drawable


I want to achieve this shadow effect as a background drawable for my RelativeLayout:

enter image description here

I am trying to get the denoted effects in my layout. Here's the description:

A: Light Stroke around the RelativeLayout

B: Shadow under the layout and a slight shadow to the right and left of the layout

What I have so far:

<?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="1dp"
        android:bottom="1dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>

What more should I add to get the displayed result?


Solution

  • You could use CardView also.

    http://developer.android.com/training/material/lists-cards.html

    Just add your own elevation and you are ready to go.