Android Shape属性(内含一个Button完整的xml定义)
来源:互联网 发布:sql注入的防御 编辑:程序博客网 时间:2024/05/16 10:52
<?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:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:useLevel=["true" | "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>
参考链接:http://blog.csdn.net/iispring/article/details/50437731
当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。angle必须为45的整数倍)
<span style="font-size:14px;">solid:实心,就是填充的意思android:color指定填充的颜色gradient:渐变android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。stroke:描边android:width="2dp" 描边的宽度,android:color 描边的颜色。我们还可以把描边弄成虚线的形式,设置方式为:android:dashWidth="5dp" android:dashGap="3dp"其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。corners:圆角android:radius为角的弧度,值越大角越圆。我们还可以把四个角设定成不同的角度,方法为:<corners android:topRightRadius="20dp" 右上角 android:bottomLeftRadius="20dp" 右下角 android:topLeftRadius="1dp" 左上角 android:bottomRightRadius="0dp" 左下角 /></span>
参考链接:
shape 介绍
http://www.oschina.net/question/166763_34833
百度经验
http://jingyan.baidu.com/article/86112f13513f4127379787b0.html
layer-list介绍
http://blog.csdn.net/evn512457/article/details/20467509
在学习xml定义Drawable时,发现xml的属性很多,。shape经常遇到,记录一下
还有一段:
完整的 按钮xml定义,通过
android:background="@drawable/button_state"
调用即可 。
button_state.xml
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?></span><span style="font-size:18px;"><selector xmlns:android="http://schemas.android.com/apk/res/android"></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <item android:state_pressed="false"></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> shape drawable xml文件中定义的一个几何图形,定义在res/drawable/目录下,文件名filename称为访问的资源ID</span><span style="font-size:18px;"> 在代码中通过R.drawable.filename进行访问,在xml文件中通过@[package:]drawable/filename进行访问。</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> android:shape=["rectangle" | "oval" | "line" | "ring"]</span><span style="font-size:18px;"> shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)</span><span style="font-size:18px;"> 下面的属性只有在android:shape="ring时可用:</span><span style="font-size:18px;"> android:innerRadius 尺寸,内环的半径。</span><span style="font-size:18px;"> android:innerRadiusRatio浮点型,以环的宽度比率来表示内环的半径,</span><span style="font-size:18px;"> 例如,如果android:innerRadiusRatio,表示内环半径等于环的宽度除以5,这个值是可以被覆盖的,默认为9.</span><span style="font-size:18px;"> android:thickness尺寸,环的厚度</span><span style="font-size:18px;"> android:thicknessRatio浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",</span><span style="font-size:18px;"> 那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的,默认值是3.</span><span style="font-size:18px;"> android:useLevelboolean值,如果当做是LevelListDrawable使用时值为true,否则为false.</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <shape</span><span style="font-size:18px;"> xmlns:android="http://schemas.android.com/apk/res/android"</span><span style="font-size:18px;"> android:shape="rectangle"></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 圆角</span><span style="font-size:18px;"> android:radius 整型 半径</span><span style="font-size:18px;"> android:topLeftRadius 整型 左上角半径</span><span style="font-size:18px;"> android:topRightRadius 整型 右上角半径</span><span style="font-size:18px;"> android:bottomLeftRadius 整型 左下角半径</span><span style="font-size:18px;"> android:bottomRightRadius 整型 右下角半径</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <corners</span><span style="font-size:18px;"> android:radius="8dp"</span><span style="font-size:18px;"> android:topLeftRadius="8dp"</span><span style="font-size:18px;"> android:topRightRadius="8dp"</span><span style="font-size:18px;"> android:bottomLeftRadius="8dp"</span><span style="font-size:18px;"> android:bottomRightRadius="8dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 渐变色</span><span style="font-size:18px;"> android:startColor 颜色值 起始颜色</span><span style="font-size:18px;"> android:endColor 颜色值 结束颜色</span><span style="font-size:18px;"> android:centerColor 整型 渐变中间颜色,即开始颜色与结束颜色之间的颜色</span><span style="font-size:18px;"> android:angle 整型 渐变角度(PS:当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。angle必须为45的整数倍)</span><span style="font-size:18px;"> 0 度 时,centerColor颜色竖直居中,90度时,centerColor水平居中</span><span style="font-size:18px;"> android:type ["linear" | "radial" | "sweep"] 渐变类型(取值:linear、radial、sweep)</span><span style="font-size:18px;"> linear 线性渐变,这是默认设置</span><span style="font-size:18px;"> radial 放射性渐变,以开始色为中心。</span><span style="font-size:18px;"> sweep 扫描线式的渐变。</span><span style="font-size:18px;"> android:useLevel ["true" | "false"] 如果要使用LevelListDrawable对象,就要设置为true。设置为true无渐变。false有渐变色</span><span style="font-size:18px;"> android:gradientRadius 整型 渐变色半径.当 android:type="radial" 时才使用。单独使用 android:type="radial"会报错。</span><span style="font-size:18px;"> android:centerX 整型 渐变中心X点坐标的相对位置</span><span style="font-size:18px;"> android:centerY 整型 渐变中心Y点坐标的相对位置</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <gradient</span><span style="font-size:18px;"> android:startColor="#F5F5F5"</span><span style="font-size:18px;"> android:centerColor="#696969"</span><span style="font-size:18px;"> android:endColor="#F5F5F5"</span><span style="font-size:18px;"> android:angle="90"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 内边距,即内容与边的距离</span><span style="font-size:18px;"> android:left 整型 左内边距</span><span style="font-size:18px;"> android:top 整型 上内边距</span><span style="font-size:18px;"> android:right 整型 右内边距</span><span style="font-size:18px;"> android:bottom 整型 下内边距</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <padding</span><span style="font-size:18px;"> android:left="10dp"</span><span style="font-size:18px;"> android:top="10dp"</span><span style="font-size:18px;"> android:right="10dp"</span><span style="font-size:18px;"> android:bottom="10dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> size 大小</span><span style="font-size:18px;"> android:width 整型 宽度 0dp则为包裹自己</span><span style="font-size:18px;"> android:height 整型 高度</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <size</span><span style="font-size:18px;"> android:width="0dp"</span><span style="font-size:18px;"> android:height="0dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 内部填充</span><span style="font-size:18px;"> android:color 颜色值 填充颜色</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <solid</span><span style="font-size:18px;"></span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 描边</span><span style="font-size:18px;"> android:width 整型 描边的宽度</span><span style="font-size:18px;"> android:color 颜色值 描边的颜色</span><span style="font-size:18px;"> android:dashWidth 整型 表示描边的样式是虚线的宽度, 值为0时,表示为实线。值大于0则为虚线。</span><span style="font-size:18px;"> android:dashGap 整型 表示描边为虚线时,虚线之间的间隔 即“ - - - - ”</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <stroke</span><span style="font-size:18px;"> android:width="1dp"</span><span style="font-size:18px;"> android:color="#FFFFFF"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"> </shape></span><span style="font-size:18px;"> </item></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!-- 按下按钮--></span><span style="font-size:18px;"> <item android:state_pressed="true" ></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <shape</span><span style="font-size:18px;"> xmlns:android="http://schemas.android.com/apk/res/android"</span><span style="font-size:18px;"> android:shape="rectangle"></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <corners</span><span style="font-size:18px;"> android:radius="8dp"</span><span style="font-size:18px;"> android:topLeftRadius="8dp"</span><span style="font-size:18px;"> android:topRightRadius="8dp"</span><span style="font-size:18px;"> android:bottomLeftRadius="8dp"</span><span style="font-size:18px;"> android:bottomRightRadius="8dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <gradient</span><span style="font-size:18px;"> android:startColor="#D3D3D3"</span><span style="font-size:18px;"> android:centerColor="#4F4F4F"</span><span style="font-size:18px;"> android:endColor="#D3D3D3"</span><span style="font-size:18px;"> android:angle="90"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <padding</span><span style="font-size:18px;"> android:left="12dp"</span><span style="font-size:18px;"> android:top="12dp"</span><span style="font-size:18px;"> android:right="8dp"</span><span style="font-size:18px;"> android:bottom="8dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <size</span><span style="font-size:18px;"> android:width="0dp"</span><span style="font-size:18px;"> android:height="0dp"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <!--</span><span style="font-size:18px;"> 内部填充</span><span style="font-size:18px;"> android:color 颜色值 填充颜色</span><span style="font-size:18px;"> --></span><span style="font-size:18px;"> <solid</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"></span><span style="font-size:18px;"> <stroke</span><span style="font-size:18px;"> android:width="1dp"</span><span style="font-size:18px;"> android:color="#4F4F4F"</span><span style="font-size:18px;"> /></span><span style="font-size:18px;"> </shape></span><span style="font-size:18px;"> </item></span><span style="font-size:18px;"></selector></span>
0 0
- Android Shape属性(内含一个Button完整的xml定义)
- android shape.xml 属性详解
- android shape.xml 属性详解
- Android Button的Selector+Shape
- [android]使用shape来定义控件的一些显示属性
- android shape的属性
- android shape 的属性
- Android shape的属性
- Android中xml中shape的属性助记
- Android中xml中shape的属性助记
- android 使用Xml文件定义Shape
- Android Button Maker(在线生成android shape xml文件的工具),真方便!
- 完整的定义事物属性
- Android selector自定义shape的button样式
- Android button边框线,只定义一个边框的颜色
- android 自定义button shape
- android中shape的属性
- Android中shape的属性
- 热血军团-vSyncCount
- EF基础知识概览
- C语言产生随机字符串
- iOS面试题集锦附答案及必需具备的知识
- poj3299 Humidex(water)
- Android Shape属性(内含一个Button完整的xml定义)
- Spark的Master分析1(主备切换机制原理分析)
- Android 创建抽屉导航
- JAVA对象数组的初始化
- POJ 2082Lost Cows<>
- 机器学习好总结
- HBase客户端API使用
- Bootstrap、hcharts、百度地图、jquery插件库
- Meteor Showerpoj3669