繁体   English   中英

定义要查看的顶部和底部阴影

[英]define top and bottom shadow to view

我正在尝试通过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>

也许有人知道我的意思,也可能是解决方案!?

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

它在顶部绘制一条线,在底部绘制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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM