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 ...
随机推荐
- 【WCF全析(一)】--服务协定及消息模式
上周微软开发布会说.NET支持完全跨平台和并开放Core源码的新闻,让我们顿时感到.NET要迎来它的春天.虽然早在几年前.NET就能开发Android和IOS,但是这次的跨平台把Linux都放到了微软 ...
- Objective - C - 添加类目 - NSDate
1.类目为系统内部的类或者是没有源代码的类添加方法,不有添加实例变量 2.添加的方法会成为原类的一部分,子类照样可以使用 3.类目的文件名为原类名+文件名 4.既可以添加实例方法,也可以添加类方法 X ...
- websql的添加和查询
openDatabase 我们可以使用这样简单的一条语句,创建或打开一个本地的数据库对象 var db = openDatabase('testDB', '1.0', 'Test DB', 2 * 1 ...
- 我个人结合到老师的来理解的——Asp.net Webform的页面生命周期
1.分析请求的资源路径,寻找目录中对应的资源文件,若无法找到资源文件,则返回404错误2.分析资源文件的Page命令,通过Page指令找到代码文件和类 3.将页面文件和类一起编译生成最终的类(仅仅在第 ...
- 利用BeautifulSoup抓取新浪网页新闻的内容
第一次写的小爬虫,python确实功能很强大,二十来行的代码抓取内容并存储为一个txt文本 直接上代码 #coding = 'utf-8' import requests from bs4 impor ...
- css 取消默认的padding
;;} --透明 兼容写法 filter:alpha(opacity=90);-moz-opacity:0.9; -khtml-opacity: 0.9;opacity: 0.9;
- DSP学习中遇到的几个问题(初级)
1..c和.asm 文件分别为C语言和汇编语言的源文件. 2..cmd是存储器分配说明文件,主要功能是指定工程中的各段分配到那段存储器中,比如有片内RAM(起始地址,大小)和SDRAM等.这些要根据平 ...
- Linux课程实践二:编译模块实现内核数据操控
一.内核模块原理 1. Linux内核增加功能 Linux内核整体结构很庞大,包含了很多的组件,现在有两种方法将需要的功能包含进内核当中: - 静态加载:将所有的功能都编译进Linux内核. - 动态 ...
- python之路——面向对象(基础篇)
面向对象编程:类,对象 面向对象编程是一种编程方式,此编程方式的落地需要使用 "类" 和 "对象" 来实现,所以,面向对象编程其实就是对 "类&quo ...
- jQuery插件制作方法
html页面:<h1>Hello My name is Alex,i from china.</h1> 1.无参数实现文字阴影效果 测试代码: $("h1" ...