Drawable简单使用

来源:互联网 发布:java电商项目经验 编辑:程序博客网 时间:2024/04/30 12:56

Android文档这样定义Drawable的:

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就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable),我们根据画图的需求,创建相应的可画对象,就可以将这个可画对象当作一块“画布(Canvas)”,在其上面操作可画对象,并最终将这种可画对象显示在画布上,有点类似于“内存画布“。

 

下面的一个自定义View显示了ShapeDrawable的一些简单使用方式:

 

程序运行效果如下图:

原创粉丝点击