Shape Drawable Resources
1,示例

它们的代码如下:
shape_oval.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#fa1621"
android:gradientRadius="50"
android:startColor="#f793ac"
android:type="sweep"/>
<size
android:width="72dp"
android:height="72dp"/>
<!--<solid android:color="#e3e3e3"/>-->
</shape>
shape_rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="#fa1621"
android:gradientRadius="50"
android:startColor="#f793ac"
android:type="radial"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
<size android:width="72dp" android:height="72dp" />
</shape>
shape_ring.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:thickness="2dp"
android:innerRadius="30dp"
android:useLevel="false">
<!--<gradient-->
<!--android:endColor="#fa1621"-->
<!--android:gradientRadius="50"-->
<!--android:startColor="#f793ac"-->
<!--android:type="radial"/>-->
<!--<padding-->
<!--android:left="10dp"-->
<!--android:top="10dp"-->
<!--android:right="10dp"-->
<!--android:bottom="10dp" />-->
<stroke
android:width="1dp"
android:color="color"
android:dashWidth="1dp"
android:dashGap="1dp" />
<solid android:color="#f8a17e" />
<size android:width="72dp" android:height="72dp"/>
</shape>
shape_line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<!-- 显示一条虚线,破折线的宽度为 dashWith,破折线之间的空隙的宽度为 dashGap,当 dashGap=0dp 时,为实线 -->
<stroke
android:dashGap="3dp"
android:dashWidth="2dp"
android:width="1dp"
android:color="#777777" /> <!-- 虚线的高度 -->
<size android:height="2dp" />
</shape>
ring_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="5555"
android:thicknessRatio="2"
android:useLevel="false">
<!--android:innerRadiusRatio="5555"含义:按比值计算内圆半径,整个图形宽度/该值,就是36dp/5555=0.006480648dp-->
<!--android:thicknessRatio="2"含义:按比值计算外环厚度。整个图形宽度/该值 就是36dp/2 = 18dp -->
<solid android:color="#ff0000" />
<size android:width="36dp" android:height="36dp"/>
</shape>
如图:
oval_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<size
android:width="16dp"
android:height="60dp"/>
<solid android:color="#e3e3e3" />
</shape>
注意,虽然shape="oval",且width=16dp,height=60dp,但是在使用的时候将控件比如imageview或textview的高宽设置成一样就是正圆。
2,语法
其中android:shape有4个类型,rectangle 矩形,oval椭圆,line线条,ring环形。
<shape>有6个子元素。<corners>圆角,<gradient>渐变颜色,<padding>内边距,<size>大小,<solid>填充,<stoke>描边。
<?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>
3,各元素属性详解
3.1<shape>形状
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:shape |
形状 |
枚举 |
rectagle矩形|正方形,oval椭圆|正圆, line水平直线,ring环形 |
画line时,用<stroke>定义线的高度 |
|
android:innerRadius |
内半径 |
尺寸 |
内圆的半径。一个尺寸值(dip等等)或者一个尺寸资源。 |
只在android:shape="ring"有效 注意,android:innerRadiusRatio 和 android:thicknessRatio 指定的都是一个被除数,比值。 |
|
android:thickness |
外环厚度 |
尺寸 |
外环的厚度,是一个尺寸值或尺寸的资源 |
|
|
android:innerRadiusRatio |
内圆半径比值 |
float |
按比值计算内圆半径,整个图形宽度/该值 例如,如果android:innerRadiusRatio="5", 则,内圆半径=整个图形宽度的宽度/5。 这个值会被android:innerRadius重写。默认值是9 见上面 ring_circle.xml |
|
|
android:thicknessRatio |
外环厚度比值 |
float |
按比值计算外环厚度。整个图形宽度/该值 例如,如果android:thicknessRatio="2", 则,外环厚度=整个图形宽度/2。 这个值是被android:innerRadius重写,默认值是3。 |
|
|
android:useLevel |
是否用作图层 |
bool |
如果用在 LevelListDrawable里,那么就是true。 如果通常不出现则为false。 |
3.2<size>大小
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:width |
长度 |
尺寸 |
||
|
android:height |
高度 |
尺寸 |
3.3<padding>内边距
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:left |
左边距 |
尺寸 |
||
|
android:top |
上边距 |
尺寸 |
||
|
android:right |
右边距 |
尺寸 |
||
|
android:bottom |
下边距 |
尺寸 |
3.4<corners>圆角
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:radius |
四角的弧度 |
尺寸 |
设置0dp,无圆角 设置>1dp, 有圆角 值越大角越圆 |
只适用于rectagle |
|
android:topRightRadius |
右上角弧度 |
尺寸 |
||
|
android:bottomLeftRadius |
右下角弧度 |
尺寸 |
||
|
android:topLeftRadius |
左上角弧度 |
尺寸 |
||
|
android:bottomRightRadius |
左下角弧度 |
尺寸 |
3.5<stroke> 描边
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:width |
描边的宽度 |
尺寸 |
||
|
android:color |
描边的颜色 |
颜色 |
||
|
android:dashWidth |
边框分段长度 |
尺寸 |
2属性要同时设置 |
|
|
android:dashGap |
边框分段间隙 |
尺寸 |
3.6<solid>填充
|
属性 |
含义 |
类型 |
取值 |
备注 |
|
android:color |
填充的颜色 |
颜色 |
3.7<gradient> 渐变颜色
|
属性 |
含义 |
类型 |
取值 |
|
android:startColor |
渐变开始颜色 |
颜色 |
|
|
android:centerColor |
渐变中间颜色 |
颜色 |
|
|
android:endColor |
渐变结束颜色 |
颜色 |
|
|
android:angle |
渐变角度 |
整字 |
0,默认值表示从左到右渐变90表示从下到上渐变, 取值必须是45的倍数 |
|
android:centerX |
渐变中心相对于x轴位置 |
小数 |
0-1.0 |
|
android:centerY |
渐变中心相对于y轴位置 |
小数 |
0-1.0 |
|
android:type |
渐变的样式 |
枚举 |
linear线性渐变radial环形渐变sweep |
|
android:gradientRadius |
渐变半径 |
小数 |
android:type="radial"必填 |
|
android:useLevel |
是否用作图层 |
布尔 |
true用于LevelListDrawable |
Shape Drawable Resources的更多相关文章
- layer-list shape drawable 层叠背景 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android Drawable - Shape Drawable使用详解(附图)
TIPS shape图形 –简单介绍 shape图形 –如何画? shape图形 –参数详细解析 shape图形 –如何用? shape图形 –实际开发应用场景 shape图形简单介绍 用xml实现一 ...
- [安卓]应用程序资源(App Resources)
谷歌推荐我们,在开发安卓系统应用程序的时候,要把资源从代码中分离出来,这样便于我们单独维护它们.采取分离的资源设计,我们还可以提供可选资源,支持特定的设备配置譬如不同的语言或屏幕尺寸,随着越来越多的A ...
- Drawable(1)各种Drawable Resource介绍
简介 Drawable Resources(可绘资源) 是一系列可以在屏幕上被绘制的资源文件,它不只是图片,可以是 xml文件,在xml文件中配置各种绘制参数. 常见Drawable Resource ...
- 有关Color和Drawable你所不知道的那些内容
Android开发中,我们经常会用到Color或Drawable,有时他们是可以混用的,有时却有严格的区别. Drawable 体系结构 Drawable是可绘制物件的一般抽象.与View不同,Dra ...
- android:shape属性详解
这一类的shape定义在xml中 file location: res/drawable/filename.xml The filename is used as the resource ID.(这 ...
- 系统的Drawable(一)
系统的Drawable(一) 学习自 <Android 开发艺术探索> <官方文档> https://www.cnblogs.com/popfisher/p/6238119.h ...
- [转]android中drawable资源的解释及例子
原文链接: http://blog.csdn.net/wode_dream/article/details/38584693 文章中的内容参考Dev Guide中的Drawable R ...
- Drawable资源的初步使用
刚開始接触到Android的时候,看到类似以下的一个Button: 当时感觉这种button有点像Material Design风格.真的以为是裁剪好的图片,好奇心驱使我上网查找实现的方法,原来不是裁 ...
随机推荐
- ci框架(codeigniter)Email发送邮件、收件人、附件、Email调试工具
ci框架(codeigniter)Email发送邮件.收件人.附件.Email调试工具 Email 类 CodeIgniter 拥有强大的 Email 类来提供如下的功能: 多 ...
- Java高并发实战,锁的优化
锁优化 这里的锁优化主要是指 JVM 对 synchronized 的优化. 自旋锁 互斥同步进入阻塞状态的开销都很大,应该尽量避免.在许多应用中,共享数据的锁定状态只会持续很短的一段时间.自旋锁的思 ...
- java 8种基本类型与对应的包装类
数据类型 包装类 字节长度 默认值 有效位 byte Byte 1 0 -128~127 short Short 2 0 -32768~32767 int Integer 4 0 -2^31-1~2^ ...
- Ubuntu 16.04安装WinRAR/7-Zip(基于CrossOver)
基于CrossOver的WinRAR/7-Zip有如下缺点: 1.不能像Windows那样右键菜单解压 可以解决的问题: 1.可以使用提供的浏览工具进行文件选择再解压,只是在操作上多一步. 2.类似百 ...
- cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64
ed2k://|file|cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64_dvd_9056935.iso|43471 ...
- 必测的支付漏洞(一)——使用fiddler篡改支付金额
互联网产品中常会遇到支付功能,测试人员测试这部分功能时一定要重视,因为如果这部分出现了较严重的bug,将会给公司带来不小的经济损失!如果你测出了问题领导也一定会高兴的!因此测试优先级很高,但具有一定难 ...
- STM32F104VG (一)中断与外部中断
一.基础知识 1.ARM的中断优先级分硬件优先级和软件优先级两种 当中软件优先级又由抢占优先级和响应优先级组成 2.中断的优先级採用编号小优先的原则. 3.普通情况: 1).假设设定了软件优先级.先看 ...
- UML——用例图
用例图是在需求分析阶段开发人员和用户对需求规格达成的某种共识.它描写叙述了待开发系统的功能需求. UML视频使我们对用例图的基本组成元素.属性.粒度等有了理论上的理解,我们还须要自己亲自己主动手画一画 ...
- Mac OS X 10.10下Versions crash的问题
升级完系统.Versions由于兼容性到问题,各种闪退,网上搜索了一下.知乎到一个帖子提到了暂时解决的方法,例如以下: Blackpixel 正在研究此崩溃的修复方案.暂时解决方式例如以下: 在文本编 ...
- 万一的Delphi消息教程
http://www.cnblogs.com/del/category/134064.html