概述
Class Overview
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 是对 "something that can be drawn." 的一般抽象。通常你处理的 drawable 是被检索到的能画一些东西在屏幕上的资源。Drawable 类为处理一个底层的可以采用多种形式的可视化资源提供了一套一般的 api。不像 View,Drawable 没有任何的设备来接受事件或者其他的用户交互。
In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:
- The
setBounds(Rect)
method must be called to tell the Drawable where it is drawn and how large it should be. All Drawables should respect the requested size, often simply by scaling their imagery. A client can find the preferred size for some Drawables with thegetIntrinsicHeight()
andgetIntrinsicWidth()
methods. - The
getPadding
method can return from some Drawables information about how to frame content that is placed inside of them. For example, a Drawable that is intended to be the frame for a button widget would need to return padding that correctly places the label inside of itself. - The
setState(int[])
method allows the client to tell the Drawable in which state it is to be drawn, such as "focused", "selected", etc. Some drawables may modify their imagery based on the selected state. - The
setLevel(int)
method allows the client to supply a single continuous controller that can modify the Drawable is displayed, such as a battery level or progress level. Some drawables may modify their imagery based on the current level. - A Drawable can perform animations by calling back to its client through the
Drawable.Callback
interface. All clients should support this interface (viasetCallback(Drawable.Callback)
) so that animations will work. A simple way to do this is through the system facilities such assetBackgroundDrawable(Drawable)
andImageView
.
- Bitmap: the simplest Drawable, a PNG or JPEG image.
- 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.
- States: a compound drawable that selects one of a set of drawables based on its state.
- Levels: a compound drawable that selects one of a set of drawables based on its level.
- Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.
Developer Guides
For more information about how to use drawables, read the Canvas and Drawables developer guide. For information and examples of creating drawable resources (XML or bitmap files that can be loaded in code), read the Drawable Resources document.
最后
以上就是洁净爆米花为你收集整理的android.graphics.drawable.Drawable的全部内容,希望文章能够帮你解决android.graphics.drawable.Drawable所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复