关于Android xml 绘图

关于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=""   //虚线间隔的宽度
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值