Home
JavaEE
Java GUI
Framework
DHtml
Android
插画
教程下载

ATOM 2.0   RSS 2.0
Add to iGoogle Add to Live.com
  • 今天终于收到金山快盘的邀请码
  • 利用最短ie判断在不同浏览器上播放背景音乐
  • 对插画方面的一点感受与回忆
  • 网上看到的两个死里逃生的图片,记录一下
  • 今天开通了糖果社区,附几个激活码
  • 终于可以实现我的多个微博实时同步了
  • 备案和现场拍照就是对站长们的瞎折腾
  • 对Android在互联网应用开发上的纠结
  • 收藏夹中的书签都没了,决定写一个自已的书签管理器
  • 测试自已整理的本机的webapps客户端发送博文能否成功。
  • 今天开通了糖果社区,附几个激活码
  • 终于可以实现我的多个微博实时同步了
  • 备案和现场拍照就是对站长们的瞎折腾
  • 昨天借用飞姐的佳作做的一个浪漫爱情网页
  • 有几个腾讯微博的邀请码(实时更新)
  • BB的网站移到了GAE-JAVA上了
  • 一个基于GAE Python Web.py和JQuery的留言本程序
  • 类许愿墙的一个告白网站和一个电子书网站
  • Android中用Bitmap获取图片中某个区域的图象
  • 对暴力破解带密码的QQ相册的可行性分析
  • 对淘宝web旺旺版一些通讯接口的研究

Android中,Drawable接口及其子类的使用方法

posted by David Chen at January 20, 2009, 1:27 PM    

        A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with
Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides
a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View,
a Drawable does not have any facility to receive events or otherwise interact with the user.
Drawable是一个可画对象,可以用它在屏膜上画内容,也可以直接取得已的图等。
Drawable d = this.getResources().getDrawable(R.drawable.a1);
// this指代Activity, R.drawable.a1是在\res\drawable文件夹中的名称为a1的图。

常见的几种Drawable对象类型:
Bitmap: the simplest Drawable, a PNG or JPEG image.
// 一般用于处理jpg和png图

Nine Patch: an extension to the PNG format allows it to specify information about
how to stretch it and place things inside of it.
// 用于如何缩放和放要想你的东西到图里面的扩展的PNG格式

Shape: contains simple drawing commands instead of a raw bitmap, allowing it to
resize better in some cases.

Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
LayerDrawable(Drawable[] array);
用于图层方式存取多个Drawable,可以用getDrawable(int index)取得其中一个Drawable,对应setLayer(int);

States: a compound drawable that selects one of a set of drawables based on its state.
addState(int[] stateSet, Drawable drawable);
An array of resource Ids to associate with the image. Switch to this image by calling setState().
为不同的状态存取不同的Drawable,通过指定状态的id值,可以取得如获得焦点,失去焦点等时的不同图像
如:addState( new int[]{R.attr.state_focused, R.attr.state_pressed}, ... ); 对应setState(int[]);

Levels: a compound drawable that selects one of a set of drawables based on its level.
addLevel(int low, int high, Drawable drawable)
可以指定在不同的级别中显示不同的图
如:addLevel(1, 3, ...); // 在第1到3级的时候显示相应的图,对应setLevel(int)


Scale: a compound drawable with a single child drawable, whose overall size is
modified based on the current level.
ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight)
// 这是一个可以缩放的drawable,可以将图缩放到指定的大小

例:
Drawable[] array = new Drawable[] {
        this.getResources().getDrawable(R.drawable.a1),
        this.getResources().getDrawable(R.drawable.a2),
        this.getResources().getDrawable(R.drawable.a3),
        this.getResources().getDrawable(R.drawable.a4)
};
LayerDrawable ld = new LayerDrawable( array );

ImageButton imgBtn = new ImageButton( this );
imgBtn.setImageDrawable( ld.getDrawable(2) );
// 显示a3这个图
Labels:   Java    Android  
Trackback:   http://cwq.iou1314.com/android-drawable_a353
微博最近更新
[2010-07-31 16:33]    今天下午又将昨天赢的哎齐出来了,郁闷,一进一出,要有入没出才行啊。
[2010-07-31 07:40]    昨晚又去啊泄度开台,呢次赢左差唔多3旧水,下周星期一请假,回郁南去转社保和入党资料。
本站内的任何文章,只代表个人意见或学习所用,如有版权声明,请尊重作者的劳动成果,在转载时请保留原始链接并注明出处。
Power by David's PhpCms, © 2007 - 2010 CWQ.IOU1314.COM All Rights Reserved.