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 ...
随机推荐
- openstack vm_lifecycle
nova instance状态:power_state, vm_state, task_state 2015-09-22 Openstack 185 nova instance有3种状态:power_ ...
- 《大道至简》第三章读后感+ppt课后作业
大道至简读后感 ——第三章团队 古人云“三人为众”,众则是指团体或团队.对于一个团队而言,重要的是凝聚力,大家能在一起把拳头握紧那么产生的力量就不紧紧是能以1+1=2 来 ...
- VS2010安装帮助文档出现错误
安装VS2010后的帮助文档安装出现错误:未能在指定文件夹中创建本地存储区 安装完VS2010后,出现错误,取消后 再安装MSDN 打开“Help Library 管理器 - Microsoft He ...
- Gson运用
输出对象或者对象的list时,我们一般都是重写toString,和遍历list,但是使用Gson输出对象或者对象的list会非常方便. Gson输出list或者对象.Gson数据没有格式化. impo ...
- mybatis读取配置文件报错:Could not find resource configuration.xml
今天用idea编译mybatis的java项目时,一直报错,找不到config.xml 查看class文件夹,确实没有xml文件 也就是说,xml文件没在编译范围内 在pom.xml中,把xml文件加 ...
- php sleep()的实时输出打印,清除ob缓冲区
@ini_set('implicit_flush',1);ob_implicit_flush(1);@ob_end_clean(); echo 1;//echo str_repeat('', 1024 ...
- Getting Started
https://developers.google.com/v8/get_started Getting Started This document introduces some key V8 co ...
- Python全栈开发day7
一.Python生成器/迭代器 1 2 3 4 5 6 7 8 9 10 11 12 #!/bin/env python # -*- coding:utf-8 -*- def shaw(n): ...
- 那些可能被你忽略的MySQL优化技巧
说明:本文中的内容适用于MySQL5.1-5.6版本,不保证新的版本中仍然适用; 且只针对于大部分常见应用场景,是否有效果应以基于实际业务数据的测试为准. 1 优先把列设置为NOT NULL 允许NU ...
- Qt 自定义消息窗口
用于设置取消时,询问是否保存修改的DLGvoid SetWindow::cancelButton() { if( m_IsChange) { QMessageBox msgBox; msgBox.se ...