View的绘制

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

public class

Canvas

extends Object
java.lang.Object
   ↳android.graphics.Canvas

Public Constructors
Canvas()
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时间一层层传递下去。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值