How to get shadow on android linear layout?-ThrowExceptions

Exception or error:

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?

How to solve:

As far as I know there is no way to apply a shadow to a View object. I suggest you take a look at nine patches, I have used them to make a shadow.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

(see also this answer Custom ImageView with drop shadow)

###

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/

Leave a Reply

Your email address will not be published. Required fields are marked *