销售类网站模板,高端网吧电脑配置,网站的登录弹窗怎么做,右翼网站转载源:http://blog.csdn.net/harvic880925/article/details/41850723 一、简单使用 刚开始#xff0c;就先不讲一堆标签的意义及用法#xff0c;先简单看看shape标签怎么用。 1、新建shape文件 首先在res/drawable文件夹下#xff0c;新建一个文件#xff0c;命名为#…转载源:http://blog.csdn.net/harvic880925/article/details/41850723 一、简单使用 刚开始就先不讲一堆标签的意义及用法先简单看看shape标签怎么用。 1、新建shape文件 首先在res/drawable文件夹下新建一个文件命名为shape_radius.xml 内容是这样的先不需要理解先看shape怎么用 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android corners android:radius20dip/ solid android:color#ff00ff/ /shape 2、添加到控件中 在定义好shape文件后下一步就是将其添加到控件中添加到控件中一般是使用设置background属性将其为控件背景下面我们将其设置为MainActivity对应的布局中activity_main.xml将其设为TextView的背景看显示出来 是什么样子的。 [html] view plaincopy RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:toolshttp://schemas.android.com/tools android:layout_widthmatch_parent android:layout_heightmatch_parent tools:contextcom.harvic.tryshape.MainActivity TextView android:layout_widthwrap_content android:layout_heightwrap_content android:layout_margin50dip android:textstring/hello_world android:backgrounddrawable/shape_radius/ /RelativeLayout 显示出来的结果是这样的 二、基本属性corners、gradient、padding、size、solid、stroke 上面给大家简单的讲了下shape标签组的简单使用方法下面就具体讲讲shape标签里所具有的几个子标签及所具有的属性。 1、Corners [html] view plaincopy corners //定义圆角 android:radiusdimension //全部的圆角半径 android:topLeftRadiusdimension //左上角的圆角半径 android:topRightRadiusdimension //右上角的圆角半径 android:bottomLeftRadiusdimension //左下角的圆角半径 android:bottomRightRadiusdimension / //右下角的圆角半径 Corners标签是用来字义圆角的其中radius与其它四个并不能共同使用。 Android:radius定义四个角的的圆角半径。 其它四个是逐个字义每个角的圆角半径。 使用 控件布局 [html] view plaincopy RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:layout_widthmatch_parent android:layout_heightmatch_parent TextView android:layout_width100dp android:layout_height100dp android:layout_margin50dip android:textstring/hello_world android:backgrounddrawable/shape_radius/ /RelativeLayout shape定义 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android corners android:radius20dip/ solid android:color#ffff00/ /shape 效果 2、solid solid用以指定内部填充色 只有一个属性 [html] view plaincopy solid android:colorcolor / 在上面的例子中我们就将填充色指定为#ffff00了如果我们不加圆角只使用填充色即将shape变成这样子 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android solid android:color#ffff00/ /shape 那效果就是这样的 3、gradient gradient用以定义渐变色可以定义两色渐变和三色渐变及渐变样式它的属性有下面几个 [html] view plaincopy gradient android:type[linear | radial | sweep] //共有3中渐变类型线性渐变默认/放射渐变/扫描式渐变 android:angleinteger //渐变角度必须为45的倍数0为从左到右90为从上到下 android:centerXfloat //渐变中心X的相当位置范围为01 android:centerYfloat //渐变中心Y的相当位置范围为01 android:startColorcolor //渐变开始点的颜色 android:centerColorcolor //渐变中间点的颜色在开始与结束点之间 android:endColorcolor //渐变结束点的颜色 android:gradientRadiusfloat //渐变的半径只有当渐变类型为radial时才能使用 android:useLevel[true | false] / //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果 首先有三种渐变类型分别是linear线性渐变、radial放射性渐变、sweep扫描式渐变 1先看看这几个属性的使用方法 [html] view plaincopy android:type[linear | radial | sweep] android:startColorcolor //渐变开始点的颜色 android:centerColorcolor //渐变中间点的颜色在开始与结束点之间 android:endColorcolor //渐变结束点的颜色 android:gradientRadiusfloat //渐变的半径只有当渐变类型为radial时才能使用 下面我们使用三色渐变来看看这三种渐变方式都是怎么显示的如果不使用centerColor属性就是双色渐变这个属性是可选的 需要注意的一点是在构造放射性渐变时要加上android:gradientRadius属性渐变半径即必须指定渐变半径的大小才会起作用下面列出这三个渐变方式的shape代码供大家参考 线性渐变 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android gradient android:typelinear android:startColor#ff0000 android:centerColor#00ff00 android:endColor#0000ff/ /shape 放射性渐变 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android gradient android:typeradial android:startColor#ff0000 android:centerColor#00ff00 android:endColor#0000ff android:gradientRadius100/ /shape 扫描式渐变 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android gradient android:typesweep android:startColor#ff0000 android:centerColor#00ff00 android:endColor#0000ff/ /shape 可见放射性渐变只是比其它两个多了个android:gradientRadius属性 2、android:angle属性仅对线性渐变有效 [html] view plaincopy android:angleinteger //渐变角度必须为45的倍数0为从左到右90为从上到下 我们在上面的三种渐变上都加上angle属性看看效果如何 能过跟上一个图对比可以发现angle属性确实只对线性渐变有效其它两种渐变方式都没有任何动静下面是此时的线性渐变shape代码 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android gradient android:typelinear android:startColor#ff0000 android:centerColor#00ff00 android:endColor#0000ff android:angle45/ /shape 3、android:centerX与android:centerY centerX、centerY两个属性用于设置渐变的中心点位置仅当渐变类型为放射渐变时有效类型为分数或小数不接受Dimension。默认值是0.5有效值是0.0~1.0超出该范围后会看不出渐变效果。centerX、centerY的取值其实是宽和高的百分比不难理解下面看代码 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android gradient android:typesweep android:startColor#ff0000 android:centerColor#00ff00 android:endColor#0000ff android:centerX0.2 android:centerY0.8/ /shape 取宽度的20%和高度的80%的位置作为新的渐变原点效果是这样的 4android:useLevel useLevel属性通常不使用。该属性用于指定是否将该shape当成一个LevelListDrawable来使用默认值为false。 4、stroke 这是描边属性可以定义描边的宽度颜色虚实线等 [html] view plaincopy stroke android:widthdimension //描边的宽度 android:colorcolor //描边的颜色 // 以下两个属性设置虚线 android:dashWidthdimension //虚线的宽度值为0时是实线 android:dashGapdimension / //虚线的间隔 上面各个属性的意义如下 我们使用绿色虚线描边虚线高度是20dp虚线宽度为10dp虚线间距为1dp: [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android stroke android:width20dp android:color#00ff00 android:dashWidth10dp android:dashGap1dp / /shape 从效果图中我们也能清晰的看出这三个参数width、dashwidth、dashGap之间的区别 5、size和padding 这两个基本上不怎么用因为他们所具有的功能控件本身也能实现。 size:是用来定义图形的大小的。 [html] view plaincopy size android:widthdimension android:heightdimension / padding用来定义内部边距 [html] view plaincopy padding android:leftdimension android:topdimension android:rightdimension android:bottomdimension / 三、Shape的属性rectangle、oval、line、ring 上面我们讲了Shape的子标签的的作用但Shape本身还没讲Shape自已是可以定义当前Shape的形状的比如上面的矩形还有椭圆形线形和环形这些都是通过Shape标签的 shape属性来定义的Shape标签总共有下面几个属性我们一个个讲 [html] view plaincopy android:shape[rectangle | oval | line | ring] shape的形状默认为矩形可以设置为矩形rectangle、椭圆形(oval)、线性形状(line)、环形(ring) 下面的属性只有在android:shapering时可用 android:innerRadius 尺寸内环的半径。 android:innerRadiusRatio 浮点型以环的宽度比率来表示内环的半径 android:thickness 尺寸环的厚度 android:thicknessRatio 浮点型以环的宽度比率来表示环的厚度例如如果android:thicknessRatio2 android:useLevel boolean值如果当做是LevelListDrawable使用时值为true否则为false. 可见只有第一个shape是可用的其它五个都是shape等于ring时所特有的。 注意无论这里shape取什么形状他的子标签都是可用的但有时并不会有效果比如在shape为椭圆时那corners标签就不会有效果很显然的道理。下面一个个看看各个形状都是怎么样的 1、rectangle (矩形) 这就是上一节我们使用的形状当我们不指定shape属性时默认就是矩形的。 控件代码 [html] view plaincopy LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:layout_widthmatch_parent android:layout_heightmatch_parent android:orientationhorizontal TextView android:layout_width300dp android:layout_height100dp android:layout_margin10dp android:textColor#ffffff android:textSize18sp android:textStylebold android:backgrounddrawable/try_shape_3/ /LinearLayout shape代码 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android android:shaperectangle solid android:color#ff00ff/ /shape 对应图形 2、oval椭圆 控件代码不变下面是shape代码 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android android:shapeoval solid android:color#ff00ff/ /shape 对应图形控件大小的矩形所对应的椭圆 3、line(线形) 没觉得这个能有什么用……也不讲了没什么意思 4、ring环形 还记得他所特有的几个属性么 [html] view plaincopy android:innerRadius 尺寸内环的半径。 android:thickness 尺寸环的厚度 android:innerRadiusRatio 浮点型以环的宽度比率来表示内环的半径 例如如果android:innerRadiusRatio表示内环半径等于环的宽度除以5这个值是可以被覆盖的默认为9. android:thicknessRatio 浮点型以环的宽度比率来表示环的厚度例如如果android:thicknessRatio2 那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的默认值是3. android:useLevel boolean值如果当做是LevelListDrawable使用时值为true否则为false. 这么几个属性无外乎就是定义环形的内环尺寸和环的宽度。 举个例子 控件定义 [html] view plaincopy LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:layout_widthmatch_parent android:layout_heightmatch_parent android:orientationhorizontal TextView android:layout_width300dp android:layout_height100dp android:layout_margin10dp android:textColor#ffffff android:textSize18sp android:textStylebold android:backgrounddrawable/try_shape_2/ /LinearLayout shape定义这里一定要要加上useLevel属性并定义为false不然没有效果 [html] view plaincopy ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/android android:shapering android:innerRadius20dp android:thickness50dp android:useLevelfalse solid android:color#ff00ff/ /shape 效果图 源码地址http://download.csdn.net/detail/harvic880925/8249629 请大家尊重原创者版权转载请标时出处http://blog.csdn.net/harvic880925/article/details/41850723 谢谢。转载于:https://www.cnblogs.com/imqsl/p/6561173.html