Shape的用法:
<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 左上圆角半径
<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 左下圆角半径
代码顺序从上而下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 填充色 --> <solid android:color="#ff0000"></solid> <!-- 边框线 --> <stroke android:width="1dp" android:color="#ffffff"></stroke> <!-- 圆角半径 --> <corners android:radius="5dp"></corners> <!-- 大小 --> <size android:width="100dp" android:height="100dp"></size> </shape>
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <!-- 填充色 --> <solid android:color="#ff0000"></solid> <!-- 边框线 --> <stroke android:width="5dp" android:color="#00ff00"></stroke> <!-- 大小 --> <size android:width="100dp" android:height="100dp"></size> </shape>
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadius="40dp" android:thickness="10dp" android:useLevel="false"> <!-- innerRadius圆环内部半径 thickness厚度 useLevel用户层 --> <!-- 填充色 --> <solid android:color="#ff0000"></solid> <!-- 边框线 --> <stroke android:color="#000000" android:width="2dp"></stroke> <!-- 大小 --> <size android:width="110dp" android:height="110dp"></size> </shape>
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%"> <shape android:shape="ring" android:innerRadius="20dp" android:thickness="5dp" android:useLevel="false"> <gradient android:startColor="#ff0000" android:centerColor="#00ff00" android:endColor="#0000ff" android:type="sweep" android:useLevel="false"/> <size android:width="100dp" android:height="100dp"></size> </shape> </rotate>
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%"> <shape android:shape="ring" android:innerRadius="20dp" android:thickness="5dp" android:useLevel="false"> <gradient android:startColor="#ffffff" android:centerColor="#ffffff" android:endColor="#ff0000" android:type="sweep" android:useLevel="false"/> <size android:width="100dp" android:height="100dp"></size> </shape> </rotate>