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

前端 未结 6 1601
野趣味
野趣味 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:14

    onDraw() is called when invalidate() is called.

    But you should know for ViewGroups: onDraw() will not be called like you expect. Rather, onDispatchDraw().

    However, in a ViewGroup you can call setWillNotDraw(false) in the constructor to make onDraw() to be called on invalidate().

    Take a look at this answer

提交回复
热议问题