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 ...
随机推荐
- interface接口
当一个抽象类中的方法都是抽象的时候,这时可以将该抽象类用另一种形式定义和表示,就是接口 interface. 定义接口使用的关键字不是class,是interface.接口中常见的成员: 这些成员都有 ...
- FastDFS分布式文件系统
FastDFS分布式文件系统 阅读目录 相关文章 1 分布式文件系统介绍 2 系统架构介绍 3 FastDFS性能方案 4 Linux基本命令操作 5 安装VirtualBox虚拟机并配置Ubuntu ...
- CSS之 float 属性
特性: float的设计初衷仅仅是文字环绕效果 浮动具有破坏性,会使父容器高度塌陷 清除浮动方法: 1.脚底插入cleart:both 2.父元素BFC(IE8+)/haslayout(IE6/7 ...
- java虚拟机指令dup的理解
举个例子: public class ExceptionTest{ void cantBeZero(int i) throws Exception{ throw new Exception(); } ...
- hibernate使用注解简化开发
简述 在编写hibernate的时候,需要将实体类映射到数据库中的表.通常需要一个配置文件(hibernate.cfg.xml),一个实体类(XX.Java),还有一个映射文件(XX.hbm.xml) ...
- 关于python如果没有numpy模块如何处理
1.在python中,你在python的shell输入>>>import numpy 但是编译器告诉你没有numpy库,这时候你就要导入python库,那么如何导入呢 2.收下访问h ...
- PHP备忘录
file_exists()在判断文件是否存在的时候是递归判断每个目录是不是有执行权限. Echo输出大字符串速度慢:打开apache配置项‘deflate’进行压缩输出.
- LeetCode 217. Contains Duplicate (包含重复项)
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- 机器学习之决策树(ID3 、C4.5算法)
声明:本篇博文是学习<机器学习实战>一书的方式路程,系原创,若转载请标明来源. 1 决策树的基础概念 决策树分为分类树和回归树两种,分类树对离散变量做决策树 ,回归树对连续变量做决策树.决 ...
- java时间格式
Calendar startdate = Calendar.getInstance(); startdate.setTime(new Date()); //当前时间 startdate.add(Cal ...