覆盖的OnDraw()或绘制()?OnDraw

2023-09-06 13:37:12 作者:爱情,没有错

我的项目是基于surfaceView和到现在为止我有所有我在OnDraw中渲染其中我重写。一切似乎是确定。

My project is based on surfaceView and up until now I've had all of my rendering in onDraw which I am overriding. All seemed to be OK.

不过,我刚刚更新了我的SDK,现在它给了我一个错误,告诉我​​:

However, I've just updated my SDK and now it gives me an error telling me:

可疑的方法调用;或许应该叫画,而不是OnDraw的

Suspicious method call; should probably call "draw" rather than "onDraw"

可能有人请解释这两者之间的区别是什么?

Could someone please explain the difference between these two?

我读过四处撒网一些类似的问题,但我还没有发现,我明白的解释。

I've read some similar questions around the net but I've not found an explanation that I understand.

感谢

推荐答案

SurfaceView.draw()基本要求 View.draw(); 如果你想实现你的绘图,你应该这样做的 View.onDraw(),这是为你实现甚至说,在源$ C ​​$ C意见。

SurfaceView.draw() basically calls View.draw(); If you want to implement your drawing, you should do it in View.onDraw() which is for you to implement which even says in the source code comments.

该方法被ViewGroup.drawChild()把每个子视图   绘制自己。这场平局()方法是一个实现细节,不   拟重写或从其他地方的其他称为   比ViewGroup.drawChild()。

This method is called by ViewGroup.drawChild() to have each child view draw itself. This draw() method is an implementation detail and is not intended to be overridden or to be called from anywhere else other than ViewGroup.drawChild().

至于它们之间的区别: 绘制():

As for difference between them: draw():

13416        /*
13417         * Draw traversal performs several drawing steps which must be executed
13418         * in the appropriate order:
13419         *
13420         *      1. Draw the background
13421         *      2. If necessary, save the canvas' layers to prepare for fading
13422         *      3. Draw view's content
13423         *      4. Draw children
13424         *      5. If necessary, draw the fading edges and restore layers
13425         *      6. Draw decorations (scrollbars for instance)
13426         */

的OnDraw()是空的。它为你实现。

onDraw() is empty. Its for you to implement.