android shape 大全 (转)
1. 各属性的配置语法
在项目 res/drawable 文件夹中创建一个以 shape 为根节点的 XML 文件,基本语法如下:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] // 4种形状分别为: 矩形、椭圆、线、圆环
android:innerRadius="integer" // 形状为圆环时的 圆环内半径
android:thickness="integer" // 形状为圆环时是 圆环的厚度 (外半径 - 内半径)
android:useLevel=["true" | "false"]> // 通常为 false, 否则可能图形不显示
<!-- 宽高尺寸(如果没指定, 通常跟随控件的宽高) -->
<size
android:width="integer"
android:height="integer" />
<!-- 形状的颜色 -->
<solid
android:color="color" />
<!-- 形状的颜色(用多种颜色梯度渐变来表示, 会被上面的 solid 元素指定的颜色会相互覆盖) -->
<gradient
android:startColor="color" // 渐变的开始颜色
android:centerColor="integer" // 渐变的中间过渡颜色
android:endColor="color" // 渐变的结束颜色
android:centerX="float" // 渐变开始的中心点X坐标(相对于形状的宽度), 值范围 0.0 ~ 1.0
android:centerY="float" // 渐变开始的中心点Y坐标(相对于形状的高度), 值范围 0.0 ~ 1.0
android:angle="integer" // 渐变方向的角度, 0 为从左到右, 90 为从下到上, 该值必须为 45 的倍数
android:gradientRadius="integer" // 渐变的圆半径, 仅在 android:type="radial" 时适用
android:type=["linear" | "radial" | "sweep"] // 渐变的类型, 分别为: 线性渐变(默认)、径向渐变、流线型渐变
android:useLevel=["true" | "false"] /> // 如果形状用作 LevelListDrawable, 则此值为 true; 一般为false
<!-- 边框 -->
<stroke
android:width="integer" // 边框的厚度
android:color="color" // 边框的颜色
android:dashWidth="integer"
android:dashGap="integer" />
<!-- 4个角的角度半径 -->
<corners
android:radius="integer" // 统一设置4个角的角度半径, 会被下面具体某个角覆盖
android:topLeftRadius="integer" // 左上角 角度半径
android:topRightRadius="integer" // 右上角 角度半径
android:bottomLeftRadius="integer" // 左下角 角度半径
android:bottomRightRadius="integer" /> // 右下角 角度半径
<!-- 内边距 -->
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
</shape>
PS: 如果需要空心的形状,则必须指明 solid 颜色为透明色,否则某些机器系统中可能会出现黑底。
2、在项目 res/layout 布局文件中引用:
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/my_shape"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_shape"/>
3. 具体形状的配置
1、矩形 ( rectangle )
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 边框 -->
<stroke
android:color="#00FF00"
android:width="3dp"/>
<!-- 矩形梯度颜色 -->
<gradient
android:startColor="#FF0000"
android:centerColor="#FFFF00"
android:endColor="#0000FF"
android:angle="90"/>
<!-- 4 个角的角度半径 -->
<corners
android:bottomLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
2、椭圆 ( oval )
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!-- 尺寸(如果宽高相同, 则便是圆) -->
<size
android:width="200dp"
android:height="130dp"/>
<!-- 边框 -->
<stroke
android:color="#00FFFF"
android:width="1dp"/>
<!-- 矩形梯度颜色(如果需要椭圆环, 可以用 solid 指定形状颜色为透明) -->
<gradient
android:startColor="#FF0000"
android:centerColor="#FF00FF"
android:endColor="#FFFF00"
android:type="sweep"/>
</shape>
3、线段( line )
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<!-- 如果指定尺寸, 则线段为该尺寸宽高的矩形中间的一条线, 没有指定则跟随控件宽高 -->
<size
android:width="200dp"
android:height="100dp"/>
<!-- 线段的 颜色 和 线宽(厚度) 由 stroke 元素指定-->
<stroke
android:color="#000000"
android:width="5dp"/>
</shape>
4、圆环 ( ring )
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="90dp"
android:thickness="5dp"
android:useLevel="false">
<!-- 圆环颜色 -->
<solid
android:color="#FF0000"/>
</shape>
PS: 通过配置空心椭圆也可以达到圆环的效果
android shape 大全 (转)的更多相关文章
- Android shape与selector标签使用
原文地址:Android shape与selector标签使用 Android中提供一种xml的方式,让我们可以自由地定义背景,比较常用的就是shape标签和selector标签 shape shap ...
- android shape使用总结
今天使用到shape,这个里面有很多属性,在这里我记录一下各个属性的使用的情况以及所代表的意思 <?xml version="1.0" encoding="utf- ...
- android 权限大全
教程 博客 淘帖 论坛›eoe·Android开发资源区›Android开发实例教程 191507 12 / 2 页下一页 android 权限大全 『癲瘋霸気』 于 2013-4-3 10: ...
- 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 ...
随机推荐
- NDK Jni 开发(1)
1. 学习地址 http://my.oschina.net/lifj/blog/177087 http://www.cnblogs.com/devinzhang/archive/2012/02/29/ ...
- python 中的enumerate()函数的用法
enumerate函数说明: 函数语法:enumerate(可遍历的对象,索引号开始的值).enumerate(sequence, [start=0]) 功能:将可循环序列sequence以start ...
- 怎么样防止Sql注入
(1)对于动态构造SQL查询的场合,可以使用下面的技术: 第一:替换单引号,即把所有单独出现的单引号改成两个单引号,防止攻击者修改SQL命令的含义.再来看前面的例子,“SELECT * from Us ...
- Jfinal配置不得不注意的问题
问题摘要 使用jfinal mvc开发的时候,输出配置环境一定要注意,因为jfinal项目的依赖与log4j,等全部是在此目录下. 使用eclipse做演示一般有两种情况 1. WebContent\ ...
- dubbo 笔记-XML配置文件简介
<dubbo:service/> 服务配置,用于暴露一个服务,定义服务的元信息,一个服务可以用多个协议暴露,一个服务也可以注册到多个注册中心. eg.<dubbo:service r ...
- Java集合框架体系详细梳理,含面试知识点。
一.集合类 集合的由来: 面向对象语言对事物都是以对象的形式来体现,为了方便对多个对象的操作,就需要将对象进行存储,集合就是存储对象最常用的一种方式. 集合特点: 1,用于存储对象的容器.(容器本身就 ...
- 217. Contains Duplicate (leetcode)
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- OSW 快速安装部署
关于在运行Oracle的环境下部署OSW具体好处不再多说,只需要知晓,在日常Oracle定位各类故障,osw的数据可以协助诊断问题.MOS很多文档也多处提到需要osw的监控数据. 一.前期资料准备 1 ...
- 2.动手实操Apache ZooKeeper
Tips 做一个终身学习的人! 日拱一卒,功不唐捐. 在本节中,我们将讲解如何下载并安装Apache ZooKeeper,以便我们可以直接开始使用ZooKeeper. 本部分旨在通过提供详细的安装和使 ...
- <ul>标签设计简单导航栏
当我们刚开始学习html/css的时候,对于padding .float.行内元素.块级元素用起来可能会混淆,但是呢我们可以通过一个简单的nav案例来清楚各自具体作用. 1.首先我们创建一个大的容器, ...