在android侧抽屉中创建这样的阴影

时间:2016-04-20 09:16:30

标签: android

如何在android侧抽屉中创建这样的影子? 请帮忙。

2 个答案:

答案 0 :(得分:1)

我正在添加如上添加

的新布局

答案 1 :(得分:0)

<强> 1。为阴影创建自定义drawable,例如shadow_right.xml

shadow_right.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="2dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">

        <shape android:shape="rectangle">
            <corners android:radius="0dp" />
            <!-- change angle value below and see the effect-->
            <gradient
                android:angle="0"
                android:centerColor="#14000000"
                android:endColor="#44000000"
                android:gradientRadius="2" />

        </shape>
    </item>
</layer-list>

<强> 2。添加drawable即shadow_right作为背景

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">

        <View
              android:id="@+id/viewRight"
              android:layout_width="10dp"
              android:layout_height="match_parent"
              android:layout_alignParentRight="true"                
              android:layout_marginTop="0dp"
              android:background="@drawable/shadow_right"
              android:visibility="visible" />

</RelativeLayout>

第3。替换shadow_right.xml中的颜色值