View.onDraw() - 当它被调用?当它、View、onDraw

2023-09-06 01:21:25 作者:清莲茉茉

我把Log.d()调用到我的扩展视图的OnDraw(),这样我就可以看多久,什么时候获取调用。它被调用时认为,这是不奇怪的实例。但后来我发现,它被要求由的onTouchEvent(处理每一个水龙头),即使我的code有没有做任何事情远程相关图形。然而,在意见文档,我似乎无法找到任何东西时的OnDraw( )实际被调用。我真的不关心我在这里特别项目(这不会导致我的一个问题),我只是想知道是否有什么地方列表或东西,显示操作的查看订单,特别是什么原因引起的的OnDraw()来调用。

I put a Log.d() call into the onDraw() of my extended View, so I could see how often and when it's getting called. It gets called upon instantiation of the view, which is not surprising. But then I notice, it gets called on every tap that is handled by onTouchEvent(), even though my code there isn't doing anything remotely related to graphics. However, in the documentation for Views, I can't seem to find anything about when onDraw() is actually called. I'm not really concerned about my particular project here (this doesn't cause a problem for me), I would just like to know if there is a list somewhere or something that shows the order of operations for a View, particularly what causes onDraw() to get called.

推荐答案

AFAIK,视图的OnDraw()被调用时:

AFAIK, a View's onDraw() is called when:

在该视图最初绘制 当invalidate()被称为在视图 The view is initially drawn Whenever invalidate() is called on the view

失效等可能由您或系统需要时调用。例如,很多意见而改变他们如何看onTouch,就像一个EditText得到一个轮廓和光标,或在pressed状态的按钮时。由于这一点,视图是重绘的联系。

Invalidate can be called by you or the system whenever needed. For example, a lot of Views change how they look onTouch, like an EditText getting an outline and cursor, or a button being in the pressed state. Due to this, Views are redrawn on touch.

我同意,这将是不错的一份文件,详细视图的工作,以及如果存在的话,有人知道在哪里可以找到它,请告诉我们。

I agree that it would be nice to have a document that detailed the working of Views, and if one exists and somebody knows where to find it, please let us know.