1

I'm trying to create a background drawable resource in XML that is translucent, but with a solid shadow.

This is what I have so far:

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

      <item>
         <shape  android:shape="rectangle" >
         <padding
              android:top="-2dp"
              android:left="-2dp"
              android:right="2dp"
              android:bottom="2dp"
            />
        <gradient 
              android:startColor="@android:color/transparent"
              android:centerColor="#33333333"
              android:endColor="#aa666666"
              android:angle="90"/>
        </shape>
     </item>

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

I'm using a gradient shape as the background, which unfortunately obscures the translucency of the background shape. I only want to draw the gradient 2px to the right and bottom of the background shape, is that possible?

TheFlash
  • 5,997
  • 4
  • 41
  • 46
StackOverflowed
  • 5,854
  • 9
  • 55
  • 119

1 Answers1

2

Try this...

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

  <item android:right ="2dp"
      android:bottom ="2dp">

     <shape  android:shape="rectangle" >
     <padding
          android:left="2dp"
          android:top="2dp"
        />  
     <corners android:radius="3dp" />    

     <gradient 
          android:startColor="@android:color/transparent"
          android:centerColor="#33333333"
          android:endColor="#aa666666"
          android:angle="90"/>
    </shape>
 </item>

<!-- Background -->
<item>
<shape android:shape="rectangle" >
        <solid android:color="#99000000" />
        <corners android:radius="3dp" />
</shape>
</item>
</layer-list>
TheFlash
  • 5,997
  • 4
  • 41
  • 46