0 votes
in Programming by (2k points)

I'm trying to adding drop shadow to rectangle i made on xml. the rectangle with corners android:radius="100dp" and the shadow i create by photoshop and edited with 9.Path. but the shadow not look good because the rectangle change is height in some cases. this is how i create the rectangle with the shadow:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <item android:top="9dp"  
        android:drawable="@drawable/drop_shadow3"
        >
    </item>

    <item  android:bottom="8dp" android:right="0dp"   android:left="0dp">
        <shape android:shape="rectangle" >
          <corners android:radius="100dp"/>

            <gradient
                android:endColor="#838383"
                android:startColor="#838383" />
        </shape>
    </item>

</layer-list>

What is the best way to do a Drop Shadow on android low api like elevation?

 

 

1 Answer

0 votes
by (1.9k points)

Try my below code to get shadow, this is working fine. adjust bottom, top, right, left to get the view as like you want

<?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:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
   android:top="5dp">
            <shape android:shape="rectangle" >
                <solid android:color="@android:color/white" />

                <corners android:radius="5dp" />
            </shape>
        </item>

    </layer-list>

 

Any doubt feel free to comment

 

 

 

...