Android样式开发——Shape

<? Xml version = "1.0" encoding = "utf-8"?>
 < Shape
     Xmlns: android = "http://schemas.android.com/apk/res/android"
     Android: shape = ["rectangle" | "oval" | "line" | "ring"]>
     < Corners
         Android: radius = " integer "
        Android: topLeftRadius = " Integer " 
        Android: topRightRadius = " Integer " 
        Android: bottomLeftRadius = " Integer " 
        Android: bottomRightRadius = " Integer " /> 
    < gradient
         Android: angle = " Integer " 
        Android: the centerX = " a float " 
        Android: centerY = " float " 
        Android: centerColor = " Integer " 
        Android: endColor = " Color " 
        Android: gradientRadius = "Integer " 
        Android: startcolor =" Color " 
        Android: type = [" Linear "|" Radial "|" Sweep "] 
        Android: useLevel = [" to true "|" to false "] /> 
    < padding
         Android: left =" Integer " 
        Android: Top = " Integer " 
        Android: right = " Integer " 
        Android: bottom = " Integer " /> 
    < size
         Android: width = " Integer " 
        Android: height = " Integer " />
    < Solid
         Android: Color = " Color " /> 
    < Stroke
         Android: width = " Integer " 
        Android: Color = " Color " 
        Android: dashWidth = " Integer " 
        Android: dashGap = " Integer " /> 
</ Shape>

shape可理解为形状,在andorid可理解可绘制形状,可以自定义形状。
android:shape=["rectangele"|"oval"|"line"|"ring"]
分别代表要绘制的图形分别为方形、圆形、线形、圆圈,四者可以选一个。
当android:shape="ring"以下属性才有效:
android:innerRadius:内环半径,单位尺寸
android:innerRadiusRatio:内环半径和环宽度的比例,默认是9。例如android:innerRadiusRatio="5",表示内环半径除以环宽度等 于5,设置该属性时,android:innerRadius属性会失效。
andorid:thickness:环的厚度,单位为尺寸。
android:tincknessRatio:环厚度和环宽度的比例,默认是3。例如android:ticknessRatio="2",表示环的厚度除以环 的宽度等于2, 设置该属性时,android:thickness会失效。
<corners>圆角,即当android:shape="rectangle"时候有效,为方形产生圆角,而不再是直角。
android:radius代表方形四个角,圆角半径一样。
android:topLeftRadius代表方形左上角半径。
android:topRightRadius代表方形右上角半径。
android:bottomLeftRadius代表方形左下角半径。
android:bottomRightRadius代表方形右下角半径。
<Gradient>指定渐变颜色
android:angle 渐变角度,默认是0,0表示从左到右,1表示从下到上,设置值必须为45的倍数。
android:centerX:渐变中心点相对x轴的位置,取值为0到1.
android:centerY:渐变中心点相对Y轴的位置,取值为0到1.
android:startColor:开始颜色
android:endColor:结束颜色
android:centerColor:起始颜色和结束颜色之间的中间颜色。
android:type渐变颜色的类型,可取linear直线型渐变,radial半径型渐变(圆形),sweep流线型渐变。
android:gradientRadius:渐变角度,但android:type="radial"才有效。
android:userLevel:使用LevelDrawable才有效。

<padding>内边距
android:left 左边距
android:right右边距
android:top上边距
android:bottom下边距
<size>形状的大小
android:width shape的宽度
android:height shape的高度
<solid>形状的填充颜色
android:color 填充颜色
<stroke>形状的边
android:width 边的厚度
android:color 边的颜色
android:dashWidth:当边为虚线时,一段边的宽度
android:dashGap:设置边为虚线,只要设置android:dashWidth时,才有效。

同时需要XML为View设置android:layerType="software"才会有虚线。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值