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

查看:28
本文介绍了在 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. onDraw(Canvas c) 是一个覆盖方法,在渲染视图时自动调用.您可以在此处进行其他绘图,例如制作圆圈、线条或任何您想要的东西.

  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.

draw(Canvas c) 用于手动将此视图(及其所有子视图)渲染到给定的画布.在调用此函数之前,视图必须已经完成了完整的布局.实现视图时,实现 onDraw(android.graphics.Canvas) 而不是覆盖此方法.如果确实需要覆盖此方法,请调用超类版本.

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天全站免登陆