14

I want to add a light shadow on the right and bottom side of the layout.I tried using android:background="@android:drawable/dialog_holo_light_frame" but it adds a thick shadow on all four sides of the layout.What drawable i need to create and set as background?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@android:drawable/dialog_holo_light_frame">
       <ImageView
                android:id="@+id/g"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:layout_gravity="center"
                android:src="@drawable/logo_icon"
                android:visibility="visible"
                android:clickable="true" />
</LinearLayout>
  • http://stackoverflow.com/questions/14930984/extending-android-view-class-to-add-a-dropshadow - Refer this link – Madhu May 06 '15 at 05:37
  • I think you need to go for custom shadow effect – VVB May 06 '15 at 05:52
  • This is what I referred and it worked . http://stackoverflow.com/questions/13005714/how-to-show-shadow-around-the-linearlayout-in-android – Prabhuraj May 06 '15 at 07:37
  • 1
    Possible duplicate of [Android LinearLayout : Add border with shadow around a linearLayout](http://stackoverflow.com/questions/24095223/android-linearlayout-add-border-with-shadow-around-a-linearlayout) – HCarrasko Dec 03 '15 at 16:44
  • Yes Nine Patch would work Do search for that , Here is the example http://stackoverflow.com/a/31722183/3303075 – NilayDani Dec 23 '16 at 10:58

3 Answers3

17

I think this may solve your problem

 <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape>
                <padding android:bottom="2dp" android:left="0dp" android:right="2dp"
                         android:top="0dp"/>
                <solid android:color="#00CCCCCC"/>
            </shape>
        </item>
        <item>
            <shape>
                <padding android:bottom="2dp" android:left="0dp" android:right="2dp"
                         android:top="0dp"/>
                <solid android:color="#10CCCCCC"/>
            </shape>
        </item>
        <item>
            <shape>
                <padding android:bottom="2dp" android:left="0dp" android:right="2dp"
                         android:top="0dp"/>
                <solid android:color="#20CCCCCC"/>
            </shape>
        </item>
        <item>
            <shape>
                <padding android:bottom="2dp" android:left="0dp" android:right="2dp"
                         android:top="0dp"/>
                <solid android:color="#30CCCCCC"/>
            </shape>
        </item>
        <item>
            <shape>
                <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp"/>
                <solid android:color="#50CCCCCC"/>
            </shape>
        </item>

        <!-- Background -->
        <item>
            <shape>
                <solid android:color="@color/white"/>
                <corners android:radius="3dp"/>
            </shape>
        </item>
    </layer-list>

Then apply it to an XML layout as a background LinearLayout android:background="@drawable/drawable_name"

N J
  • 25,967
  • 13
  • 73
  • 94
1

This is what I referred and it worked.

** 1.Add a plain LinearLayout with grey color, over which add your actual layout, with margin at bottom and right equal to 1 or 2 dp

2.Have a 9-patch image with a shadow and set it as the background to your Linear layout**

Other solutions here

Community
  • 1
  • 1
Prabhuraj
  • 868
  • 2
  • 7
  • 12
-3

Just put android:hardwareAccelerated="true" into your Manifest Application.

aMJay
  • 1,994
  • 5
  • 19
  • 29