1. 程式人生 > >Android 卡片邊框模糊陰影效果實現

Android 卡片邊框模糊陰影效果實現

1. 使用<shape>標籤實現

<?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:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="0dp" />
            <solid android:color="#0DCCCCCC" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="0dp" />
            <solid android:color="#10CCCCCC" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="0dp" />
            <solid android:color="#15CCCCCC" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="0dp" />
            <solid android:color="#20CCCCCC" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="2dp"
                android:top="0dp" />
            <solid android:color="#25CCCCCC" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="#FFFFFF" />
            <corners android:radius="4dp" />
        </shape>
    </item>
</layer-list>
用法:
<RelativeLayout
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/card_title"
            android:layout_marginBottom="50px"
            android:layout_marginLeft="30px"
            android:layout_marginRight="30px"
            android:layout_marginTop="40px"
            android:background="@drawable/card_shape"
            tools:ignore="PxUsage">

最後展現效果:

 

2.可以是用Android CardView控制元件實現,不過這個控制元件是5.0後才出現的,使用需要弄好相容的問題

 使用方法,請轉至:https://blog.csdn.net/u013651026/article/details/79000205