android控件阴影效果

使用layer-list

  • 在res/drawable下,新建background_with_shadow.xml文件,该文件代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<? xml  version = "1.0"  encoding = "utf-8" ?>
< layer-list  xmlns:android = "http://schemas.android.com/apk/res/android"  >
 
     <!-- bottom shadow -->
     < item >
         < shape  android:shape = "rectangle"  >
             <!-- from top to bottom -->
             < gradient
                 android:angle = "90"
                 android:centerColor = "#bbbbbb"
                 android:endColor = "#d5d5d5"
                 android:startColor = "#a9a09d"  />
             < corners  android:radius = "5dp"  />
         </ shape >
     </ item >
     
     <!-- content -->
     < item  android:bottom = "2dp" >
         < shape  android:shape = "rectangle"  >
             < solid  android:color = "#50c1e9"  />
             < corners  android:radius = "5dp"  />
         </ shape >
     </ item >
 
</ layer-list >

  • 效果图如下


猜你喜欢

转载自blog.csdn.net/guankai1990/article/details/71545463