Android样式开发——Shape

来源:互联网 发布:恩比德最新体测数据 编辑:程序博客网 时间:2024/06/06 09:18
<? 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"才会有虚线。


原创粉丝点击