- 浏览: 827571 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
renzhengzhi:
请教一下楼主,公有云和私有云的开发,具体要做哪些工作呢?我拿到 ...
4,云的4 种模式 -
SangBillLee:
我用了solr5.5,用SolrQuery查询,没法高亮,不知 ...
solr5.x快速入门 -
lw900925:
这翻译读起来真是别扭。
solr in action翻译-第一章1.1 -
springjpa_springmvc:
spring mvc demo教程源代码下载,地址:http: ...
Spring MVC性能提升 -
h416373073:
正遇到了此问题不知如何解决, 多谢分享
solr错误
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.
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) );
本次我们主要讲解Android平台下的各种Drawable,这里在SDK的android.graphics.drawable包下面可以看到有各种Drawable类多达十几种,它们到底之间有什么关系和区别呢?
一、AnimationDrawable
顾名思义该类主要表示动画的图形类,可以实现逐帧播放的效果,下面代码示例如下
1. 定义一个cwj_animation.xml 放到res/drawable 目录下,其中定义的属性duration为延时,单位为毫秒,而oneshot属性表示是否仅播放一次,内容为:
1 <animation-list android:id="selected" android:oneshot="false">
2 <item android:drawable="@drawable/cwj0" android:duration="30" />
3 <item android:drawable="@drawable/cwj1" android:duration="30" />
4 <item android:drawable="@drawable/cwj2" android:duration="30" />
5 <item android:drawable="@drawable/cwj3" android:duration="30" />
6 <item android:drawable="@drawable/cwj4" android:duration="30" />
7 <item android:drawable="@drawable/cwj5" android:duration="30" />
8 </animation-list>
9
10
2.在java中调用也很简单
ImageView img = (ImageView)findViewById(R.id.cwj_image); //首先声明一个ImageView对象在xml布局文件中
img.setBackgroundResource(R.drawable.cwj_animation); //我们刚才的animation定义的xml文件
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); //构造AnimationDrawable对象
frameAnimation.start() //开始播放动画
3. AnimationDrawable类还提供了一些常用的方法如下:
void stop() 停止
void addFrame(Drawable frame, int duration) 添加一帧,类似xml中的布局
Drawable getFrame(int index) 返回某帧的Drawable图形
int getNumberOfFrames() 返回总共动画帧数
boolean isOneShot() 是否仅播放一次
boolean isRunning() 是否正在播放
二、BitmapDrawable
在Android平台中对于缩放、变形的Bitmap对象由BitmapDrawable类表示,其构造方法也很简单,由于该类继承于android.graphics.drawable.Drawable,相对Drawable而言提供了更多的有关位图的操作方法,主要的构造方法如下:
BitmapDrawable() //直接构造一个空的对象,这样方式不推荐使用,SDK标记为deprecated.未来可能无法使用。
BitmapDrawable(Resources res) //从资源中构造
BitmapDrawable(Bitmap bitmap) //从Bitmap对象直接构造,但也是不推荐,而是希望用下一种
BitmapDrawable(Resources res, Bitmap bitmap) //从bitmap中创建设置初始的分辨率从res中
BitmapDrawable(String filepath) //从具体文件路径构造,也不推荐使用,而是下一种更好
BitmapDrawable(Resources res, String filepath) //同上
BitmapDrawable(InputStream is) //从输入流中构造,同样推荐下面的方法
BitmapDrawable(Resources res, InputStream is) //同上
在BitmapDrawable类中相对于Drawable类主要新增了以下几种方法,均比较实用:
final Bitmap getBitmap() 获取一个Bitmap对象
int getOpacity() //获取透明度
void setAntiAlias(boolean aa) //是否抗锯齿
void setTargetDensity(Canvas canvas) //设置目标Canvas密度
void setTargetDensity(DisplayMetrics metrics)
三、ClipDrawable
ColorDrawable
Drawable
GradientDrawable
InsetDrawable
LayerDrawable
LevelListDrawable
NinePatchDrawable
PaintDrawable
PictureDrawable
RotateDrawable
ScaleDrawable
ShapeDrawable
StateListDrawable
TransitionDrawable
以上的类型在常见的开发一般较少出现,主要是基类构造使用,Android内部的多个Widget基础控件使用了,感兴趣的网友可以查看开源GIT中的相关内容。
发表评论
-
Android SDK更新 Connection to http://dl-ssl.google.com refused 解决方法 .
2013-10-10 11:38 1183问题描述使用SDK Manager ... -
android 对话框中的进度条 (ProgressDialog)
2012-03-10 00:16 2560显然要定义对话框进 ... -
Android开发学习笔记WebView
2012-02-28 21:59 5115WebView(网络视图)能加载 ... -
Android ListView理解之BaseAdapter .
2012-02-28 21:43 2042ListView是Android开发过程中较为常见的组件之一, ... -
AsyncTask的用法
2012-02-27 21:36 887在开发Android应用时必须遵守单线程模型的原则: An ... -
android中的ellipsize
2012-02-26 17:47 1063最近为了解决某个bug,textview中内容过长的话自动 ... -
BaseExpandableListAdapter
2012-02-26 17:40 1549转载自:中国手机开 ... -
使用命令安装apk的方法
2012-02-26 15:44 1688使用命令安装apk的方法, 第一步,将应用防止在androi ... -
Android PendingIntent和Intent的区别
2012-02-16 22:39 1723以前在学习AlarmManager里面会遇到PendingI ... -
android中gallery的使用
2012-02-13 22:52 25121,创建配置文件 <?xml version=&quo ... -
android的tabHost的使用
2012-02-13 22:10 1565废话不多,直接介绍怎么使用 1,用几个tab,就建立几个ta ... -
android源码解析之二ApplicaitonInfo和PackageManager
2012-02-07 13:26 2246ApplicationInfo ApplicationIn ... -
android源码解读一(Context)
2012-02-05 21:13 4248Context类 Context是一个抽象类 public ... -
android 属性android:visibility
2012-02-05 12:16 934此属性意思是此视图是否显示, 例如RelativeLayou ... -
android默认焦点设置的方法
2012-02-05 12:13 18909在使用到文本框(EditText)来进行数据录入的时候,有时默 ... -
imageView.setScaleType
2012-02-03 17:36 5987imageView.setScaleType(ImageVie ... -
文件在SD卡存储
2012-02-02 10:47 1757手机的存储空间分俩种,一种是手机自带的,另一种是SD卡,(外存 ... -
广播接收者
2012-02-02 10:45 1213广播接受者(BroadcastReceiv ... -
android的服务
2012-02-02 10:45 974服务android中服务和window中的服务是类似的东西,服 ... -
android资源的应用
2012-02-02 10:43 1457color颜色在配置文件中定义路径:res/values/co ...
相关推荐
android 通过图片名称获取 drawable 目录下的图片 ~~~~~~~~~~~~~~~~~
OneDrawable - 仅使用一张资源图片为 View 设置具有按下效果的背景,详细原理:http://gudong.name/2017/04/05/OneDrawable.htmlGradleAdd it in your root build.gradle at the end of repositories:allprojects...
演示了各种Drawable的效果,以及自定义Drawable
依赖的drawable文件
Drawable基础Demo
Android中Drawable分类汇总,学习drawable的文档,很全
android中的drawable集合,包括Bitmap、shape、Layer、Transition等等
Android的Drawable学习Demo
Android所有系统资源图标android.R.drawable.xxx查看软件 源码地址:http://blog.csdn.net/dianyueneo/article/details/7197067
android-gif-drawable 用于在Android上显示动画GIF
文档中描述了Drawable Bitmap 几种转换方法供初学者使用。方法都是经过实践验证的。
自定义Drawable实现圆形图片和圆角图片,个人感觉挺简单的
Android中不同类型的Drawable使用
自定义Drawable 实现图片圆角、圆形、椭圆形,帮助理解自定义Drawable; 自定义Drawable 实现图片圆角、圆形、椭圆形,帮助理解自定义Drawable;
本次我们主要讲解Android平台下的各种Drawable,这里在SDK的android.graphics.drawable包下面可以看到有各种Drawable类多达十几种,它们到底之间有什么关系和区别呢?
Drawable资源管理图片处理
Android自定义Drawable的代码例子。用于演示自定义Drawable的功能,包括自定义形状、自定义水印、自定义淡出等几种类型的Drawable。
这个程序是对android的部分Drawable的实现。包括了BitmapDrawable,InsetDrawable,ClipDrawable,TransitionDrawable,GradientDrawable,ScaleDrawable,LevelListDrawable,StateListDrawable,layerDrawable。 ...
DrawableTextView.zip,自定义控件 :drawable 跟随TextView居中 The drawable follows the text centered