How can i show shadow for my linear layout. I want white colored rounded background with shadow around the linearlayout. I have done this so far. Please help me. Thanks in advance.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@xml/rounded_rect_shape"
android:orientation="vertical"
android:padding="10dp">
<-- My buttons, textviews, Imageviews go here -->
</LinearLayout>
And rounded_rect_shape.xml under xml directory
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
</shape>
Actually I agree with @odedbreiner but I put the dialog_frame inside the first layer and hide the black background under the white layer.
There is also another solution to the problem by implementing a layer-list that will act as the background for the LinearLayoout.
Add background_with_shadow.xml file to
res/drawable
. Containing:Then add the the layer-list as background in your LinearLayout.
Well, this is easy to achieve .
Just build a
GradientDrawable
that comes from black and goes to a transparent color, than use parent relationship to place your shape close to the View that you want to have a shadow, then you just have to give any values to height or width .Here is an example, this file have to be created inside
res/drawable
, I name it asshadow.xml
:Place the following code above from a
LinearLayout
, for example, set theandroid:layout_width
andandroid:layout_height
tofill_parent
and2.3dp
, you'll have a nice shadow effect on yourLinearLayout
.Note 1: If you increase
android:layout_height
more shadow will be shown .Note 2: Use
android:layout_above="@+id/id_from_your_LinearLayout"
attribute if you are placing this code inside a RelativeLayout, otherwise ignore it.Hope it help someone.
I know this is old, but most of these answers require a ton of extra code.
If you have a light colored background, you can simply use this:
set this xml drwable as your background;---
Try this.. layout_shadow.xml
Apply to your layout like this