关于Android xml 绘图
当我们想为一个Button添加背景时,但是没有合适的图片,用代码画的话太麻烦。我们这时就可以用XML来完成绘制图或画。
Bitmap,在xml中使用Bitmap很方便
···
<bitmap xmlns="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic/>
通过shape在xml中绘制各种图形
这里的属性很多,参数也很多,需要记忆下,这样用的时候才能得心应手。
属性:
1.shape –指示绘制的形状 包括 rectangle ,oval,line,ring
2.corners –当shape为rectangle设置该属性,默认为1dp
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer"
3.gradient –设置渐变
android:angle="integer"
这个属性的值必须是45的倍数,否则运行会崩。该属性用于设置渐变的角度。
这个是angle=45时的图
这个是angle=”135”时的图
android:centerX="integer" android:centerY="integer"
该属性用于设置渐变的中心位置坐标。
android:startColor=""
android:centerColor=""
android:endColor=""
该属性设置渐变的开始中间结束颜色.如上图所示。
android:gradientRadius="integer"
这个属性用于渐变的半径,>_<设置半天没看到效果。
android:type="" --linear radial(放射状的) sweep(横扫状的)
用于设置渐变的的风格。如图
4.padding 这个不用解释了,用的很多了。用个图表示下
android:top=""
android:left=""
android:right=""
android:bottom=""
5.size 指定大小,一般配合scaleType使用
android:width=""
android:height=""
6.solid 填充颜色
android:color+""
7.stroke 设置边框
androi:color=""
android:width+""
android:dashWidth="" //虚线的宽度
android:dasGap="" //虚线间隔的宽度