Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a shadow in each cell of a ListView?

I have a custom cell for an Android ListView. This custom cell is a relative layout with some views inside. There is a space between each cell, so I want to add to the bottom of the cells a shadow.

I've been googling around but couldn't found anything? I want to achieve something similar to this:

enter image description here

Thanks!

like image 630
Andres Avatar asked May 01 '13 02:05

Andres


2 Answers

Can be done in below two ways:

  1. 9-patch images - click link for understanding 9 patch
  2. Using layer-list - Create new file in "res/drawable" which contains:

     <?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>
    

Then add this layer-list file as background in your List item Layout(ie., Linearlayout or etc..).

like image 69
Vidyadhar Avatar answered Sep 30 '22 01:09

Vidyadhar


The easiest way is definitely to build the shadow into a 9-patch. An example of something like this is:

Box 9-Patch

This is way larger than it needs to be, as a 9-patch, but I wanted to make it larger for example's sake.

like image 21
Kevin Coppock Avatar answered Sep 30 '22 02:09

Kevin Coppock