【问题标题】:define top and bottom shadow to view定义要查看的顶部和底部阴影
【发布时间】:2014-08-18 11:40:53
【问题描述】:

我正在尝试通过 XML 创建一个应该如下所示的背景:

纯白色背景,在此视图的顶部和底部有渐变以显示阴影。

我知道我可以通过使用多个视图并为每个视图创建一个可绘制的背景来创建它,但我认为可能有更好的解决方案!?

我尝试使用图层列表,但因为我无法设置“heigh”和/或“alignParentBottom”或类似的东西,渐变的 alpha 太大,所以你看不到阴影...

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Drop Shadow Stack -->
    <item android:bottom="15dp">
        <shape>
            <gradient
                android:centerColor="#000"
                android:endColor="#0000"
                android:angle="90"/>
        </shape>
    </item>

    <!-- base background -->
    <item android:bottom="15dp" android:top="15dp">
        <shape android:shape="rectangle">
            <solid android:color="#fff"/>

        </shape>
    </item>

</layer-list>

也许有人明白我的意思,也许也有解决方案!?

【问题讨论】:

    标签: android background drawable shadow layer-list


    【解决方案1】:

    我找到了适合我工作的解决方案。

    它在顶部绘制一条线,在底部绘制 5dp 渐变。

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- Drop Shadow Stack -->
        <item>
            <shape>
                <gradient
                    android:centerColor="#D5E2ED"
                    android:endColor="#0000"
                    android:angle="90"/>
            </shape>
        </item>
    
        <item android:bottom="10dp">
            <shape>
                <padding android:top="1dp"/>
                <solid android:color="#D5E2ED"/>
            </shape>
        </item>
    
        <!-- base background -->
        <item android:bottom="5dp" android:top="1dp">
            <shape android:shape="rectangle">
                <solid android:color="#fff"/>
                <padding android:bottom="10dp" android:top="10dp"/>
            </shape>
        </item>
    
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多