转载来源:http://blog.youkuaiyun.com/brokge/article/details/9713041
属性:
<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"
上面填充
例子:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 填充的颜色:这里设置背景蓝色 --> <solid android:color="#419ee3" /> <!-- 边框的颜色 :不能和窗口背景色一样 --> <stroke android:width="2dp" android:color="#000000" /> <!-- 设置按钮的四个角为弧形 --> <!-- android:radius 弧形的半径 --> <corners android:bottomLeftRadius="2dip" android:bottomRightRadius="2dip" android:topLeftRadius="2dip" android:topRightRadius="2dip" /> <!-- padding:Button里面的文字与Button边界的间隔 --> <padding android:bottom="2dp" android:left="3dp" android:right="3dp" android:top="2dp" /> </shape>
效果
最后ps:androidstudio 每次都要重新打开才能看到修改后的效果。不然不论怎么修改shape ,界面布局效果预览那都不变。以前的eclipse也是这样,不知道这个问题什么时候能解决