shape属性:
Shape的属性(rectangle、oval、line、ring)
Shape自已是可以定义当前Shape的形状的,矩形,椭圆形,线形和环形;这些都是通过Shape标签的 shape属性来定义的。默认是rectangle
shape下面 一共有6个子节点, 常用的 就只有 四个,padding 和size 一般用不到。
corners ———-圆角
gradient ———-渐变
padding ———-内容离边界距离
size ————大小
solid ———-填充颜色
stroke ———-描边
定义直线:
参考链接 http://blog.youkuaiyun.com/piglovesula/article/details/24318739
shape_line
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000" />
<size android:height="0.5dp" />
</shape>
使用:
<View
android:layout_width="50dp"
android:layout_height="3dp"
android:background="@drawable/shape_line" />
定义虚线:
shape_dash_line
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<gradient
android:endColor="#FFFFFF"
android:startColor="#000000"
android:type="linear" />
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashGap="2dp"
android:dashWidth="2dp" />
<size android:width="20dp" />
</shape>
使用: 加上这一句才有效 android:layerType=”software”,不然显示的是直线
<View
android:layout_width="50dp"
android:layout_marginTop="30dp"
android:layout_height="5dp"
android:layerType="software"
android:background="@drawable/shape_dash_line"
/>
定义线性渐变:
shape_gradual_line
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
>
<gradient
android:endColor="#FFFFFF"
android:startColor="#000000"
android:type="linear" />
</shape>
使用 height=1dp是直线,height大于1dp是线性渐变的矩形
<View
android:layout_width="50dp"
android:layout_height="1dp"
android:background="@drawable/shape_gradual_line" />
定义圆角实心:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
>
<corners android:radius="20dp"/>
<solid android:color="#ff0000"/>
</shape>
定义圆角空心边框背景图:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="#ffffff" />
<stroke
android:width="2dp"
android:color="#ff0000" />
</shape>