当前位置:首页 > 芯闻号 > 充电吧
[导读]1、当测量好一个View后就可以重写onDraw()方法,并在Canvas对象上绘制所需的图形。public class Canvas extends Objectjava.lang.Object  

1、当测量好一个View后就可以重写onDraw()方法,并在Canvas对象上绘制所需的图形。

public class Canvas extends Object
java.lang.Object    ↳ android.graphics.CanvasCanvas()Construct an empty raster canvas. Canvas(Bitmap bitmap)Construct a canvas with the specified bitmap to draw into.   Class Overview

The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).

 

2、onDraw

 protected void onDraw (Canvas canvas)

Implement this to do your drawing.

参数Canvas canvas对象用来进行绘图。

Canvas canvas = new Canvas(bitmap);

bitmap用来存储所有绘制在Canvas上的像素信息。

由源码:View的绘制过程有以下几步:

1)绘制背景(background.draw(canvas))

2)绘制自己(omDraw())

3)绘制children(dispatchDraw)

4)绘制装饰(onDrawScrollBars(for instance))

View绘制过程的传递通过dispatchDraw来实现,遍历调用所有子元素的draw方法,draw时间一层层传递下去。

 

Public Constructors
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭