Adding elevation to layout

6.3k Views Asked by At

I have a custom listView and the list item that i am using is a linear layout with couple of images and text. Now i want to make this list item a bit elevated just like the pic below

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

For the background of each list item, you can use an xml drawable to achieve this effect:

mydrawable.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="@color/border_shadow"/>
            <corners android:radius="3dp" />
        </shape>
    </item>

    <item
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="3dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/white"/>
            <corners android:radius="3dp" />
        </shape>
    </item>
</layer-list>

To adjust the shadow sizes, tweak the left, right, etc. in the second item. Use it in your LinearLayout for each item as android:background="@drawable/mydrawable".