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。

见上面ring_circle.xml

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的更多相关文章

  1. layer-list shape drawable 层叠背景 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. Android Drawable - Shape Drawable使用详解(附图)

    TIPS shape图形 –简单介绍 shape图形 –如何画? shape图形 –参数详细解析 shape图形 –如何用? shape图形 –实际开发应用场景 shape图形简单介绍 用xml实现一 ...

  3. [安卓]应用程序资源(App Resources)

    谷歌推荐我们,在开发安卓系统应用程序的时候,要把资源从代码中分离出来,这样便于我们单独维护它们.采取分离的资源设计,我们还可以提供可选资源,支持特定的设备配置譬如不同的语言或屏幕尺寸,随着越来越多的A ...

  4. Drawable(1)各种Drawable Resource介绍

    简介 Drawable Resources(可绘资源) 是一系列可以在屏幕上被绘制的资源文件,它不只是图片,可以是 xml文件,在xml文件中配置各种绘制参数. 常见Drawable Resource ...

  5. 有关Color和Drawable你所不知道的那些内容

    Android开发中,我们经常会用到Color或Drawable,有时他们是可以混用的,有时却有严格的区别. Drawable 体系结构 Drawable是可绘制物件的一般抽象.与View不同,Dra ...

  6. android:shape属性详解

    这一类的shape定义在xml中 file location: res/drawable/filename.xml The filename is used as the resource ID.(这 ...

  7. 系统的Drawable(一)

    系统的Drawable(一) 学习自 <Android 开发艺术探索> <官方文档> https://www.cnblogs.com/popfisher/p/6238119.h ...

  8. [转]android中drawable资源的解释及例子

    原文链接:         http://blog.csdn.net/wode_dream/article/details/38584693 文章中的内容参考Dev Guide中的Drawable R ...

  9. Drawable资源的初步使用

    刚開始接触到Android的时候,看到类似以下的一个Button: 当时感觉这种button有点像Material Design风格.真的以为是裁剪好的图片,好奇心驱使我上网查找实现的方法,原来不是裁 ...

随机推荐

  1. 【PowerDesigner】PowerDesigner之CDM、PDM、SQL之间转换

    有关CDM.PDM.SQL之间转换以及不同数据库之间库表Sql的移植,首先要了解的是它们各自的用途.这里就简单的描述一下,不做详细的解释了. CDM:概念数据模型.CDM就是以其自身方式来描述E-R图 ...

  2. POJ 2778 (AC自动机+矩阵乘法)

    POJ 2778 DNA Sequence Problem : 给m个只含有(A,G,C,T)的模式串(m <= 10, len <=10), 询问所有长度为n的只含有(A,G,C,T)的 ...

  3. QQ - Linux中文Wiki

    QQ:http://linux-wiki.cn/wiki/zh-hans/QQ 此页由张凯于2013年7月7日 (星期日) 14:00的最后更改. 在陈泓旭和沧之声和Linux Wiki用户Chenx ...

  4. Codeforces Round #482 (Div. 2) C Kuro and Walking Route

    C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  5. CentOS7下安装单机版RabbitMQ及权限赋予

    RabbitMQ官网rpm软件包地址:https://www.rabbitmq.com/releases/ 一.安装环境: CentOS7.erlang-19.0.4-1.el7.centos.x86 ...

  6. 洛谷 P1183 多边形的面积

    P1183 多边形的面积 题目描述 给出一个简单多边形(没有缺口),它的边要么是垂直的,要么是水平的.要求计算多边形的面积. 多边形被放置在一个 X-YX−Y 的卡笛尔平面上,它所有的边都平行于两条坐 ...

  7. Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装

    这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...

  8. 获取select 选中的option中自定义的名称的之

    <select style="width: 220px;height: 20px;margin: 0 0 0 20px;" id="invest_ticket&qu ...

  9. 咏南 DELPHI DATASNAP LINUX中间件

    咏南 DATASNAP LINUX中间件   咏南 DATASNAP LINUX中间件,一套源码,同时支持WINDOWS和LINUX操作系统. 基于DELPHI 10.2 TOKYO开发 使用FIRE ...

  10. JavaScriptSerializer 序列号datatime时少了8小时

    有人说主要的因素是在于JSON格式不直接支持日期和时间. 简单一点处理办法是ToLocalTime()一下:dt = dt.ToLocalTime(); 参考http://blog.csdn.net/ ...