android shape使用总结
今天使用到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: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>
上面这段就是shape使用的格式,来看一下如何使用:
<shape>
- 定义这是一个GradientDrawable,必须作为根元素。
- android:shape
- 定义shape的值,必须是下面的之一:
- "rectangle" 矩阵,这也是默认的shape
"oval" 椭圆
"line" 一条水平的直线。这种shape必须使用 <stroke> 元素来定义这条线的宽度 - "ring" 圆环
- 下面的属性只有当 android:shape="ring"才使用:
android:innerRadius
尺寸。 内环的半径。一个尺寸值(dip等等)或者一个尺寸资源。
android:innerRadiusRatio
Float类型。这个值表示内部环的比例,例如,如果android:innerRadiusRatio = " 5 ",那么内部的半径等于环的宽度除以5。这个值会被android:innerRadius重写。 默认值是9。
android:thickness
尺寸。环的厚度,是一个尺寸值或尺寸的资源。
android:thicknessRatio
Float类型。厚度的比例。例如,如果android:thicknessRatio= " 2 ",然后厚度等于环的宽度除以2。这个值是被android:innerRadius重写, 默认值是3。
android:useLevel
Boolean类型。如果用在 LevelListDrawable里,那么就是true。如果通常不出现则为false。 <corners>
- 为Shape创建一个圆角,只有shape是rectangle时候才使用。
- android:radius
Dimension。圆角的半径。会被下面每个特定的圆角属性重写。
android:topLeftRadius
Dimension。top-left 设置左上角的半径
android:topRightRadius
Dimension。top-right 设置右上角的半径
android:bottomLeftRadius
Dimension。 设置右下角的半径
android:bottomRightRadius
Dimension。设置左下角的半径 <gradient>
- 指定这个shape的渐变颜色。
- android:angle
Integer。渐变的角度。 0 代表从 left 到 right。90 代表bottom到 top。必须是45的倍数,默认为0
android:centerX
Float。渐变中心的相对X坐标,在0到1.0之间。
android:centerY
Float。渐变中心的相对Y坐标,在0到1.0之间。
android:centerColor
Color。可选的颜色值。基于startColor和endColor之间。
android:endColor
Color。 结束的颜色。
android:gradientRadius
Float 。渐变的半径。只有在 android:type="radial"才使用
android:startColor
Color。开始的颜色值。
android:type
Keyword。渐变的模式,下面值之一: - "linear" 线形渐变。这也是默认的模式
"radial" 辐射渐变。startColor即辐射中心的颜色
"sweep" 扫描线渐变。 - android:useLevel
Boolean。如果在LevelListDrawable中使用,则为true - <padding>
内容与视图边界的距离
android:left
Dimension。左边填充距离. - android:top
Dimension。顶部填充距离.
android:right
Dimension。右边填充距离. - android:bottom
Dimension。底部填充距离. - <size>
这个shape的大小。
android:height
Dimension。这个shape的高度。
android:width
Dimension。这个shape的宽度。
注意:默认情况下,这个shape会缩放到与他所在容器大小成正比。当你在一个ImageView中使用这个shape,你可以使用 android:scaleType="center"来限制这种缩放。 - <solid>
填充这个shape的纯色
android:color
Color。颜色值,十六进制数,或者一个Color资源 - <stroke>
这个shape使用的笔画,当android:shape="line"的时候,必须设置改元素。
android:width
Dimension。笔画的粗细。
android:color
Color。笔画的颜色
android:dashGap
Dimension。每画一条线就间隔多少。只有当android:dashWidth也设置了才有效。
android:dashWidth
Dimension。每画一条线的长度。只有当 android:dashGap也设置了才有效。
android:dashGap和android:dashWidth设置这条线为虚线的,其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离, - 使用别人的一段代码:
- button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 填充 -->
<solid android:color="#ff9d77" /> <!-- 定义填充的颜色值 --> <!-- 描边 -->
<stroke
android:width="2dp"
android:color="#fad3cf" /> <!-- 定义描边的宽度和描边的颜色值 --> <!-- 圆角 -->
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" /> <!-- 设置四个角的半径 --> <!-- 间隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" /> <!-- 设置各个方向的间隔 --> </shape>
button_pressed_bg.xml的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 渐变 -->
<gradient
android:endColor="#FFFFFF"
android:gradientRadius="50"
android:startColor="#ff8c00"
android:type="radial" /> <!-- 描边 -->
<stroke
android:dashGap="3dp"
android:dashWidth="5dp"
android:width="2dp"
android:color="#dcdcdc" /> <!-- 圆角 -->
<corners android:radius="5dp" /> <!-- 间隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" /> </shape>
如何使用,看下面的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed_bg" android:state_pressed="true"></item>
<item android:drawable="@drawable/button_bg"></item> </selector>
就是这样。
android shape使用总结的更多相关文章
- android:shape
android:shape=["rectangle" | "oval" | "line" | "ring"] shape ...
- Android shape的使用(圆角矩形)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- android shape详解
shape--> shape属性: rectangle: 矩形,默认的形状,可以画出直角矩形.圆角矩形.弧形等 solid: 设置形状填充的颜色,只有android:color一个属性 andr ...
- android shape(如自定义Button)
Shape 前言:有时候会去自己去画一些Button的样式来展现在UI当中,其中主要用到的就是Shape 先来看一段代码: <?xml version="1.0" encod ...
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看 api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...
- Android Shape画圆,矩形
画圆环代码如下: 画圆环,外边的边界宽度大一点即可: <?xml version="1.0" encoding="utf-8"?> <shap ...
- ANDROID SHAPE画圆形背景_ANDROID实现角标布局
ANDROID SHAPE画圆形背景_ANDROID实现角标布局 <?xml version="1.0" encoding="UTF-8"?> &l ...
- android shape总结 和控制的风格定制
1:shape总结 1):shape文件是放置在drawable文件下的.res/drawable/filename.xml. 2):shape类型:android:shape. 一共同拥有四种:re ...
- [转]Android Shape渲染的使用(经典,学习研究不后悔)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.51cto.com/1823534/1215749 ...
随机推荐
- android嵌套unity3d
最近因为跟小伙伴在制作一个App参加比赛,由于有unity的开发经验,突发奇想的想要在Android应用中内嵌unity提供模型展示的功能. 为此,我们查阅了不少资料.大多发现的是unity中内嵌An ...
- S2SH CRUD 整合
采用的框架 Struts2+Spring4+Hbiernate4. 目录结构 : EmployeeAction: package com.xx.ssh.actions; import java. ...
- Ninject之旅之十:Ninject自定义提供者
摘要 提供者是特殊的工厂类,Ninject使用它来实例化解析类型.任何时候我们绑定一个服务类型到一个组件,我们都隐式地关联那个服务类型到一个可以实例化那个组件的提供者.这个隐藏的提供者被称为Stand ...
- 常用到的git,mvn,postgres,vim命令总结
mvn: 打包: mvn package 如果想在打包的时候跳过测试: mvn package -Dmaven.test.skip=true 使用的junit测试框架, 测试: mvn test 如果 ...
- jquery change dropdownlist selected option
<select name="corporation"> <option value="1">corporation1</optio ...
- Python 无限循环
import threading import time class CountDownTimer(threading.Thread): def __init__(self, seconds, act ...
- shared memory realm does not exist
有天启动ORACLE,碰到如下问题 提示ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist 解决 ...
- SOA架构介绍和理解
SOA架构介绍和理解 SOA的正确方法论及目标模型,其实SOA在实现架构落地上,需要考虑到对服务的组合,不断的重用现有的服务,让企业应用可以逐步集成,快速实现业务的迭代. 通过SOA架构分层将服务按照 ...
- IOS系列swift语言之课时四
今天我们要讲的主要有:下标.可为空的类型.枚举(特殊的枚举:递归枚举).原生值.关联值 首先来分析一下这个下标,就是说我们可以通过下标找到对应的值或者是改变对应的值. 其次是可为空的类型,我们要牢记所 ...
- web前端安全 XSS跨站脚本 CSRF跨站请求伪造 SQL注入
web安全,从前端做起,总结下web前端安全的几种技术: 1,XSS XSS的全称是Cross Site Scripting,意思是跨站脚本,XSS的原理也就是往HTML中注入脚本,HTML指定了脚本 ...