Drawable及其子类(BitmapDrawable、ShapeDrawable等)
2015-12-11 18:01
561 查看
一、BitmapDrawable:(.9格式的图片NinePatchDrawable类似)表示一张图片,在开发中我们可以使用原始的图片或者通过xml的方式来描述。xml描述如下:
二.ShapeDrawable:通过颜色来构造图片。xml描述如下:
三 LayerDrawable:表示一种层次化的drawable集合。
五. StateListDrawable:表示drawable集合,主要用于设置可单击的view的背景。
六.LevelListDrawable:集合中的每个Drawable都有一个等级的概念,根据不同的等级,LevelListDrawable会切换到对应的drawable。
七.TransitionDrawable:对应于 实现2个drawable之间的淡入淡出
八.InsetDrawable:对应于, 可以将其他的drawable内嵌到自己当中,并可以在四周留出一定的距离。
九. ScaleDrawable:对应于,可以根据之间的等级将指定的drawable缩放到一定的比例;
十.ClipDrawable:对应于,可以根据自己当前的等级(level)来裁剪另一个drawable.
<?xml version="1.0" encoding="utf-8"?> <bitmap android:src(图片资源id) android:antialias(是否开启抗锯齿功能) android:dither(是否开启抖动效果) android:filter(是否开启过滤) android:gravity android:mipMap android:tileMode > </bitmap>
二.ShapeDrawable:通过颜色来构造图片。xml描述如下:
<?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle | oval | line | ring" > <corners> ....适用于shape,表示四个角的角度; </corners> <gradient> ....和<solid>相互排斥,表示渐变的效果,而solid表示纯色填充; </gradient> <solid> ....表示纯色填充,用android:color可指定该颜色; </solid> <stroke> ....shape的描边 </stroke> <padding> ....表示空白 </padding> <size> ....可以表示shape的宽高 </size> </shape>
三 LayerDrawable:表示一种层次化的drawable集合。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#0ac39e" /> </shape> </item> <item android:bottom="6dp"> <shape android:shape="rectangle" > <solid android:color="#ffffff" /> </shape> </item> <item android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape android:shape="rectangle" > <solid android:color="#ffffff" /> </shape> </item> </layer-list>
五. StateListDrawable:表示drawable集合,主要用于设置可单击的view的背景。
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" android:constantSize="false" . . . > <item android:state_focused="" . . . ></item> </selector>
六.LevelListDrawable:集合中的每个Drawable都有一个等级的概念,根据不同的等级,LevelListDrawable会切换到对应的drawable。
七.TransitionDrawable:对应于 实现2个drawable之间的淡入淡出
<?xml version="1.0" encoding="utf-8"?> <transition xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/shape_drawable_gradient_linear"/> <item android:drawable="@drawable/shape_drawable_gradient_radius"/> </transition>
八.InsetDrawable:对应于, 可以将其他的drawable内嵌到自己当中,并可以在四周留出一定的距离。
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetBottom="15dp" android:insetLeft="15dp" android:insetRight="15dp" android:insetTop="15dp" > <shape android:shape="rectangle" > <solid android:color="#ff0000" /> </shape> </inset>
九. ScaleDrawable:对应于,可以根据之间的等级将指定的drawable缩放到一定的比例;
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/image1" android:scaleHeight="70%" android:scaleWidth="70%" android:scaleGravity="center" />
十.ClipDrawable:对应于,可以根据自己当前的等级(level)来裁剪另一个drawable.
<?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="vertical" android:drawable="@drawable/image1" android:gravity="bottom" />
相关文章推荐
- javascript:对象基础
- Understanding Scopes
- Nginx学习-2.1 简单实现负载均衡
- 1118有限自动机的构造与识别
- Eclipse - JAR包制作细节
- Preparing Olympiad---cf550B(DFS或者状态压缩模板)
- 创建纯css下拉菜单
- Java 多线程(六) synchronized关键字详解(牛叉)
- mysql常用字符串操作函数大全,以及实例
- git实践题目
- 深入理解 AngularJS 的 Scope
- Oracle 12c 数据库的本地连接和远程连接
- AndroidM 振动器系统
- 基于暗通道去雾算法的实现与优化(二)opencv在pc上的实现
- 马云如何识人带人
- excel常用函数及功能操作
- 哈希表的综合应用(创建、处理冲突、查找成功和失败的次数)
- 蓝桥杯——数列特征,字母图形 , 01字串 ,闰年判断
- 主备同步
- Hive 设置map 和 reduce 的个数