View.onDraw() - 当它被调用? [英] View.onDraw() --- when does it get called?

查看:306
本文介绍了View.onDraw() - 当它被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把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:

  1. 在该视图最初绘制
  2. 当<一href="http://developer.android.com/reference/android/view/View.html#invalidate%28%29">invalidate()被称为在视图
  1. The view is initially drawn
  2. 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.

这篇关于View.onDraw() - 当它被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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