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风格.真的以为是裁剪好的图片,好奇心驱使我上网查找实现的方法,原来不是裁 ...
随机推荐
- 【Intellij 】Intellij IDEA 添加jar包的三种方式
一.直接复制:(不推荐) 方法:直接将硬盘上的jar包复制粘贴到项目的lib目录下即可. 注意: 1.对于导入的eclipse项目,该方式添加的jar包没有任何反应,用make编译项目会报错 2.对于 ...
- cogs——1215. [Tyvj Aug11] 冗余电网
1215. [Tyvj Aug11] 冗余电网 ★ 输入文件:ugrid.in 输出文件:ugrid.out 简单对比 时间限制:1 s 内存限制:128 MB TYVJ八月月赛提高组 ...
- DTRACE简介(1)
https://blogs.oracle.com/swan/entry/dtrace%E7%AE%80%E4%BB%8B By samwan on 三月 20, 2007 记得几年前看过一部美国大片叫 ...
- ubuntu下进行ssh
ubuntu下进行ssh 一, 介绍 SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立 ...
- [Spring] Bean Scope Singleton cs Prototype
We can define a class to be Singleton or Prototype. If the class was defined as Prototype, then ever ...
- 图像处理之基础---基于opencv的灰度图像微分
argv分别为,可执行文件名.读入的原始图像.输出原始图像的灰度值.输出原始图像灰度值沿x轴方向的一阶微分.输出原始图像灰度值沿x轴方向的二阶微分. #include #include #includ ...
- Android学习笔记-tween动画之java实现
Android动画分为Tween动画和Frame动画,近期学习了,体tween动画,现在讲学习的心得以及相关知识介绍如下. Tween又称为补间动画,可以把对象进行缩小.放大.旋转和渐变等操作. ...
- 蓝桥 PREV-34 历届试题 矩阵翻硬币
历届试题 矩阵翻硬币 时间限制:1.0s 内存限制:256.0MB 问题描述 小明先把硬币摆成了一个 n 行 m 列的矩阵. 随后,小明对每一个硬币分别进行一次 Q 操作. 对第 ...
- Tiny4412汇编流水灯代码,Tiny4412裸机LED操作【转】
本转载自:http://www.techbulo.com/1313.html Tiny4412汇编流水灯代码,Tiny4412裸机LED操作 2014年10月20日 ⁄ 裸机程序 ⁄ 共 4171字 ...
- YTU 2898: C-Z型变换
2898: C-Z型变换 时间限制: 1 Sec 内存限制: 128 MB 提交: 53 解决: 15 题目描述 让我们来玩个Z型变换的游戏,游戏的规则如下: 给你一个字符串,将它以Z字型的形状不 ...