在Android中查看onDraw(Canvas c)与draw(Canvas c)? [英] View onDraw(Canvas c) versus draw(Canvas c) in android?

查看:103
本文介绍了在Android中查看onDraw(Canvas c)与draw(Canvas c)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发的新手,正在探索View.我遇到了已知的两种方法onDraw(Canvas c)draw(Canvas c).

I am new to android development, I am exploring about View. I come across to known two methods onDraw(Canvas c) and draw(Canvas c).

能否请我解释一下这两种方法的区别和用法?使用图像更新画布时,哪种方法可以提供更好的性能(FPS)?

Could please explain me the difference and usage of these two methods? Which method will give better performance(FPS) when updating canvas with images?

推荐答案

它们之间有区别

  1. The onDraw(Canvas c) is a override method and automatically called when the view is being rendered. Here you can do your additional drawing like make circles, lines or whatever you want.

The draw(Canvas c) is used to manually render this view (and all of its children) to the given canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.

或者用简单的话来说 draw(Canvas c)只是视图的功能,您可以在首次渲染视图后调用它.此功能可用于在任何视图上进行自定义绘图.您需要提供将在其上呈现此视图的画布,并且还必须在画布上进行所有绘制,然后才能调用此函数.

Or in simple words draw(Canvas c) is simply a function of a view that you can call after the view is rendered for the first time. This function can be used for custom drawing on any view. You need to provide the canvas on which this view will rendered and also you have to do all the drawing on the canvas before calling this function.

这篇关于在Android中查看onDraw(Canvas c)与draw(Canvas c)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆