when does the View.ondraw method get called

时间:2023-03-09 03:40:52
when does the View.ondraw method get called

a View's onDraw() is called when:

  1. The view is initially drawn
  2. Whenever invalidate() is called on the view

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.

  • If you set a background drawable for a View, then the View will draw it for you before calling back to its onDraw() method.

  • onAttachedToWindow () is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

  • invalidate() mark the area defined by dirty as needing to be drawn. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

see also:

http://*.com/questions/11912406/view-ondraw-when-does-it-get-called