【问题标题】:How to create rounded shadow - Android如何创建圆形阴影 - Android
【发布时间】:2014-02-19 13:14:24
【问题描述】:

如何在图片的椭圆中创建阴影到线性布局

我可以使用以下脚本创建阴影,但从左到右书写的厚度是相同的

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

     <!-- Drop Shadow Stack -->
     <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#00CCCCCC" />
        </shape>
    </item>
     <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#10CCCCCC" />
        </shape>
    </item>
     <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#20CCCCCC" />
        </shape>
    </item>
     <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#30CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#50CCCCCC" />
        </shape>
    </item>

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

我需要中心区域较厚但左右两侧较窄的阴影。

【问题讨论】:

  • 请详细说明您的要求
  • 问题详细,谢谢。

标签: android android-linearlayout shadow


【解决方案1】:

我建议您创建一个 9patch 并使用它,但在您的情况下,这可能不是最佳做法。因此,也许您可​​以尝试使用径向渐变,但它会因设备而异...要具有径向渐变,您可以尝试以下操作:

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

    <item>
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:endColor="#00000000"
                android:gradientRadius="360"
                android:startColor="#000000"
                android:type="radial" />
        </shape>
    </item> 
</layer-list>

编辑:再想一想,可能 9patch 最适合你...

【讨论】:

    猜你喜欢
    • 2012-12-13
    • 2016-07-16
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多