Stbdroid之ShapeDrawable
Shape可以定义矩形、椭圆形、线条、圆形
<?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>
下面是一些例子,修改上面的属性的效果图:
layout就是一个ImageView
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@drawable/shape_style" />
下面是shape的配置文件内容
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <corners android:radius="0dp" >
</corners> <stroke
android:width="10dp"
android:color="@android:color/holo_blue_light" >
</stroke> </shape>
效果如左边的图,当上面改成
android:radius="50dp"
现在看下gradient,shape的内容如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <gradient
android:endColor="#ffffffff"
android:startColor="@android:color/holo_blue_bright" >
</gradient> </shape>
效果图如下,
,
修改如下:
<gradient
android:endColor="#ffffffff"
android:startColor="#ffffffff"
android:centerColor="@android:color/holo_blue_bright"
android:angle="90" >
</gradient>
图如下
下面看下padding,首先ImageView的内容:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_icon"
android:background="@drawable/shape_style" />
shape的内容:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<solid
android:color="@android:color/holo_blue_bright"></solid>
</shape>
最后,看size和stroke
同样是ImageView:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_style" />
shape_style内容:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <size android:width="200dp"
android:height="100dp"/>
<stroke
android:width="10dp"
android:color="@android:color/holo_blue_bright" /> </shape>
在shape_style中加入android:dashWidth="5dp"和 android:dashGap="5dp",效果如下:
Stbdroid之ShapeDrawable的更多相关文章
- Android ShapeDrawable
今天做项目碰到一个这样的情况,就是颜色指示框,用的是正方形边框是黑色的,里面填充颜色,颜色值是动态的,为了解决这个问题,查了好多资料,终于找到解决的方法,利用ShapeDrawable,我们自定义一个 ...
- Android ShapeDrawable无法上色
在Android中的View设置背景时,使用ShapeDrawable有可能出现无法上色的问题(最终背景为黑色),例如,使用如下的代码为控件设置颜色时,控件背景将会变成黑色 ShapeDrawable ...
- android学习笔记33——资源ShapeDrawable
ShapeDrawable ShapeDrawable用于定义一个基本的几何图像(如,矩形.圆形.线条.......). 定义ShapeDrawable的XML文件的根元素是<shape.../ ...
- ShapeDrawable 资源
ShapeDrawable 用于定义一个基本的几何图形(如矩形.圆形.线条等),定义 ShapeDrawable 的 XML 文件的根元素是<shape.../>元素,该元素可指定如下属性 ...
- 使用(Drawable)资源———ShapeDrawable资源
ShapeDrawable用于定义一个基本的几何图形(如矩形.圆形.线条等),定义ShapeDrawable的XML文件的根元素是<shape.../>元素,该元素可指定如下属性. and ...
- 安卓自定义控件(二)BitmapShader、ShapeDrawable、Shape
第一篇博客中,我已经Canvas.Paint.Shader.Xfermode这些对象做了总结,而现在这篇文章主要介绍BitmapShader位图渲染,Xfermode如何实际应用,还有形状的绘制.不过 ...
- ShapeDrawable做放大镜效果
引用一下ShapeDrawable的类的说明: java.lang.Object ? android.graphics.drawable.Drawable ? android.grap ...
- Android ShapeDrawable之OvalShape、RectShape、PaintDrawable、ArcShape
Android ShapeDrawable之OvalShape.RectShape.PaintDrawable.ArcShape Android图形图像基础之OvalShape.RectShap ...
- 关于ShapeDrawable应用的一些介绍(中)之Gradient
版权声明:本文为博主原创文章,未经博主允许不得转载. Gradient,渐变,是在界面设计中最经常用到的一种技巧,只要涉及到颜色的处理,浓妆淡抹总相宜,说的就是它. 在Android中,当然也提供了这 ...
随机推荐
- 专访CEO何朝曦:深信服高速成长的秘诀
在深信服公司深圳总部的办公室里,要迅速找到几位高管的工位远远不如找一位女员工的座位那样容易. 深信服CEO何朝曦先生 公司里虽然女孩很少,但几乎每位女员工的工位上都有一盆绿植.相比之下,从公司CEO何 ...
- 基于KVM建立虚拟机的步骤及总结说明
1.前言 目前正在涉足云计算IaaS工作,虚拟化是IaaS的重要部分,因此这段时间对各个虚拟机化技术和工具进行研究,研究的目的不仅仅是为了会使用这个工具,而是通过研究了解技术的实现机制和原理,即知其然 ...
- 吝啬的国度(dfs+vector)
吝啬的国度 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...
- 浅析linux中的fork、vfork和clone
各种大神的混合,做个笔记. http://blog.sina.com.cn/s/blog_7598036901019fcg.html http://blog.csdn.net/kennyrose/ar ...
- shell编程之文本与日志过滤
1:grep命令: grep -v "char" file_name 匹配不包括"char"的文本 grep -n -w "char" ...
- IE7下浮动元素的内容自动换行的BUG解决方法
有时候我们想写个浮动得到这样的效果: 代码: <!doctype html> <html> <head> <meta charset="utf-8& ...
- zoj 1083 Frame Stacking
其实就是一个拓补排序.(动态记录第i个之上的j存不存在,反过来就是第j个之下的i) 首先确立每个框的位置(题目明确说了每一边都不会被完全覆盖)./*可以通过搜索,搜索到该框的所有四个角*/||如果题目 ...
- spring+hibernate基础
把数据库的配置信息写在一个文件中 jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc\:mysql\://localhost\:3306/ ...
- 最大流之sap算法
若有向图G = (V , E)满足下列条件: 1.有且仅有一个顶点S,它的入度为 0 ,这个顶点称为源点. 2.有且仅有一个顶点T,它的出度为 0 ,这个顶点称为汇点. 3.每一条弧都有一个非负数,叫 ...
- 两种写法实现Session Scope的Spring Bean
xml based: <bean id="localRepository" class="com.demo.bean.LocalRepository" s ...