Drawable简单使用
2010-08-20 17:28
267 查看
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
,
a Drawable does not have any facility to
receive events or otherwise interact with the user.
Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是
一个图层(LayerDrawable),我们根据画图的需求,创建相应的可画对象,就可以将这个可画对象当作一块“画布(Canvas)”,在其上面操作可画对象,并最终将这种可画对象显示在画布上,有点类似于“内存画布“。
下面的一个自定义View显示了ShapeDrawable的一些简单使用方式:
程序运行效果如下图:
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的一些简单使用方式:
public class TestView extends View { private ShapeDrawable mShapeDrawable; public TestView(Context context) { super(context); int x = 10, y = 10; int width = 300, height = 50; mShapeDrawable = new ShapeDrawable(new OvalShape()); //ShapeDrawable.getPaint():Returns the Paint used to draw the shape mShapeDrawable.getPaint().setColor(Color.YELLOW); mShapeDrawable.setBounds(x, y, x+width, y+height); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawColor(Color.WHITE); mShapeDrawable.draw(canvas); } }
程序运行效果如下图:
相关文章推荐
- PictureDrawable的简单使用
- AnimatedRotateDrawable的简单使用
- ScaleDrawable的简单使用
- ShapeDrawable和GradientDrawable的简单使用
- Bitmap,BitmapDrawable,BitmapFactory的简单使用,以及AssetManager的使用
- Android之ClipDrawable资源简单使用
- LevelListDrawable的简单使用
- AnimatedListStateDrawable的简单使用
- VectorDrawable的简单使用(这里不讲动画,不需要的请绕过)
- GradientDrawable 的简单使用(绘制控件的背景)
- VectorDrawable的简单使用
- RippleDrawable 的简单使用
- AnimatedVectorDrawable的简单使用
- RippleDrawable 的简单使用
- Android中AnimationDrawable使用的简单实例
- **ANDROID**# 第七章图形与图像处理(静态处理) > Bitmap是有像素点构成的点阵图。 ------ ## 使用简单的图片 ---- * 通过Drawable对象进行访问。
- RotateDrawable的简单使用
- [使用资源] 简单获取drawable下规律性命名的图片资源
- 『ANDROID』使用AnimationDrawable简单的多图片切换
- Android动画:AnimationDrawable资源的简单使用