赞
踩
1,首先了解一下layer-list中的shapr:
简介
作用:XML中定义的几何形状
位置:res/drawable/文件的名称.xml
使用的方法:
Java代码中:R.drawable.文件的名称
XML中:Android:background="@drawable/文件的名称"
属性:
<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval椭圆,line水平直线,ring环形 <shape>中子节点的常用属性: <gradient> 渐变 Android:startColor 起始颜色 Android:endColor 结束颜色 Android:angle 渐变角度,0从左到右,90表示从下到上,数值为45的整数倍,默认为0; Android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep <solid > 填充 Android:color 填充的颜色 <stroke >描边 Android:width 描边的宽度 Android:color 描边的颜色 Android:dashWidth 表示'-'横线的宽度 Android:dashGap 表示'-'横线之间的距离 <corners >圆角 Android:radius 圆角的半径 值越大角越圆 Android:topRightRadius 右上圆角半径 Android:bottomLeftRadius 右下圆角角半径 Android:topLeftRadius 左上圆角半径 Android:bottomRightRadius 左下圆角半径 <padding >填充 android:bottom="1.0dip" 底部填充 android:left="1.0dip" 左边填充 android:right="1.0dip" 右边填充 android:top="0.0dip" 上面填充
1,实现圆角阴影的原理为画两个长宽不同,背景色不同的矩形,重叠在一起就实现了阴影效果。
在res/drawable下新建shardow.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- layout background --> <item> <!-- show rectangle area --> <shape android:shape="rectangle"> <gradient android:angle="90" android:centerColor="#2F000000" android:centerX="50%" android:centerY="0" android:endColor="#1F000000" android:startColor="#1F000000" /> <corners android:bottomLeftRadius="6dip" android:bottomRightRadius="6dip" android:topLeftRadius="6dip" android:topRightRadius="6dip" /> </shape> </item> <!-- layout foreground --> <item android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="3dp"> <!-- show rectangle area --> <shape android:shape="rectangle"> <gradient android:angle="270" android:endColor="#FFFFFF" android:startColor="#FFFFFF" /> <corners android:bottomLeftRadius="4dip" android:bottomRightRadius="4dip" android:topLeftRadius="4dip" android:topRightRadius="4dip" /> </shape> </item> </layer-list>
在相应的控件中设置background即可:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-20dp"
**android:background="@drawable/shadow"**
android:orientation="vertical"
android:paddingBottom="15dp"
android:paddingTop="15dp">
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。