View.onDraw() — when does it get called?

前端 未结 6 1587
野趣味
野趣味 2020-12-29 02:42

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

6条回答
  •  粉色の甜心
    2020-12-29 03:17

    • 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.

提交回复
热议问题