1

I am trying to create an inner shadow effect to a linear layout in my android project. I couldn't come up with a way to achieve the shadow effect on all 4 sides of a view. This answer helped https://stackoverflow.com/a/11579459/15746285,but still it is giving the shadow effect to only two sides.

  <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <!-- "background shadow" -->
        <item>
            <shape android:shape="rectangle" >
                <solid android:color="#000000" />
    
                <corners android:radius="15dp" />
            </shape>
        </item>
        <!-- background color -->
        <item
            android:bottom="3dp"
            android:left="3dp"
            android:right="3dp"
            android:top="3dp">
            <shape android:shape="rectangle" >
                <solid android:color="@color/bb_grey" />
                <corners android:radius="8dp" />
            </shape>
        </item>
        <!-- over left shadow -->
        <item>
            <shape android:shape="rectangle" >
    
                <gradient
                    android:angle="180"
                    android:centerColor="@color/bb_grey"
                    android:centerX="0.9"
                    android:endColor="#99000000"
                    android:startColor="#00FF0000"
                    />
    
                <corners android:radius="8dp" />
            </shape>
        </item>
        <!-- over right shadow -->
        <item>
            <shape android:shape="rectangle" >
                <gradient
                    android:angle="360"
                    android:centerColor="@color/bb_grey"
                    android:centerX="0.9"
                    android:endColor="#99000000"
                    android:startColor="#00FF0000" />
    
                <corners android:radius="8dp" />
            </shape>
        </item>
        <!-- over top shadow -->
        <item>
            <shape android:shape="rectangle" >
                <gradient
                    android:angle="-90"
                    android:centerColor="@color/bb_grey"
                    android:centerY="0.9"
                    android:endColor="#99000000"
                    android:startColor="#00FF0000"
                    android:type="linear" />
    
                <corners android:radius="8dp" />
            </shape>
        </item>
        <!-- over bottom shadow -->
        <item>
            <shape android:shape="rectangle" >
                <gradient
                    android:angle="90"
                    android:centerColor="@color/bb_grey"
                    android:centerY="0.9"
                    android:endColor="#99121111"
                    android:startColor="#00FF0000"
                    android:type="linear" />
    
                <corners android:radius="8dp" />
            </shape>
        </item>
    </layer-list

Tried the above code but ended up with only top and bottom shadows.

ssj
  • 11
  • 1

0 Answers0