How to get shadow on android linear layout?

Martin picture Martin · Apr 2, 2011 · Viewed 66.6k times · Source

Possible Duplicate:
how to set shadow to a View in android?

In my Android app I need a layout with round corners and the background should have some transparency. For this I'm using this xml, it works fine:

customshape.xml:

<shape android:shape="rectangle"> 
    <gradient android:startColor="#E2FFFFFF" android:endColor="#E2D0E3E5" android:angle="270"/> 
    <corners android:radius="10dp" /> 
</shape>

style.xml:

<style name="LinearLayoutRoundCorners">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:background">@drawable/customshape</item>
</style>

I also need a small shadow to the right and bottom of the layout. I can not find a way to do this. I've seen a hack where you put another layout behind to make it look like a shadow but that will not work for me as my layout have transparency, so that will not look very good. How can I get a nice looking shadow on my layout without using an image as background of the layout?

Answer

javahead76 picture javahead76 · Jun 29, 2011

I know this is way late, but I was reading this question/answer combo and though of an alternative method that doesn't require an image. I threw together a post on my blog explaining. I figure it would be helpful to future visitors to have both of these answers handy here.

http://web.archive.org/web/20120520203231/http://www.anotherandroidblog.com/2011/06/29/drop-shadow-linearlayout/