简体   繁体   中英

define top and bottom shadow to view

I'm trying to create a background via XML that should look like this:

A solid white background where a gradient is on top and bottom of this view to show a dropshadow.

I know i can create this just by using multiple views and create a drawable background for each of them but i think there might be a better solution for that!?

I tried to use a layer-list but because i cant set 'heigh' and/or 'alignParentBottom' or something like that the alpha of the gradient is to much so you can't really see a shadow...

<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>

Maybe someone out there got an idea of what i mean and maybe a solution too!?

I found a solution for me to work.

It draws a line on top and a 5dp gradient on the bottom.

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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