Android translucent background with shadow

血红的双手。 提交于 2019-12-19 04:47:27

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/17801289/android-translucent-background-with-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!