What does postInvalidate() do?

后端 未结 3 1724
栀梦
栀梦 2020-11-27 04:09

What is the use of the postInvalidate() function in Android? I have been seeing this function in a lot of places. When I Googled, I came out with this much:

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 04:37

    Each class which is derived from the View class has the invalidate and the postInvalidate method. If invalidate gets called it tells the system that the current view has changed and it should be redrawn as soon as possible. As this method can only be called from your UIThread another method is needed for when you are not in the UIThread and still want to notify the system that your View has been changed. The postInvalidate method notifies the system from a non-UIThread and the View gets redrawn in the next eventloop on the UIThread as soon as possible. It is also briefly explained in the SDK documentation.

    Just compare invalidate and postInvalidate.

提交回复
热议问题