什么是postInvalidate()呢?postInvalidate

2023-09-12 01:41:32 作者:俞:俞没人,俞是乎、俞不矢志

什么是使用Android中的 postInvalidate()的功能?我已经看到这个功能在很多地方。当我用Google搜索,我想出了这么多的:

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:

postInvalidate--的发布UI线程在一个无效的请求的

postInvalidate-- post an invalidate request on the UI-thread

我不知道是什么的那句无效的请求有指。能详细这里发生了什么有人解释?

I don't know what the phrase "invalidate request" there means. Can someone explain in detail what is happening here?

推荐答案

这是从View类派生每个类都有在无效和 postInvalidate 方式。如果无效被调用它告诉,目前来看已经修改了系统,并应尽快重新绘制。由于这种方法只能从UIThread被称为另一种方法是在需要的时候你是不是在UIThread,仍然要通知你的观点已经被更改系统。所述postInvalidate方法从非UIThread通知系统和View得到尽快重新绘制在对UIThread下一事件循环。它也是briefly在SDK文档中解释。

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.

只是比较无效和 postInvalidate