postInvalidate() 有什么作用? [英] What does postInvalidate() do?

查看:77
本文介绍了postInvalidate() 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

postInvalidate() 函数在 Android 中有什么用?我在很多地方都看到过这个功能.当我用谷歌搜索时,我发现了这么多:

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 类派生的每个类都有 invalidatepostInvalidate 方法.如果 invalidate 被调用,它会告诉系统当前视图已更改,应尽快重新绘制.由于此方法只能从您的 UIThread 调用,因此当您不在 UIThread 中但仍想通知系统您的 View 已更改时,需要另一种方法.postInvalidate 方法会从非 UIThread 通知系统,并且 View 会尽快在 UIThread 的下一个事件循环中重新绘制.它也是 简要 在 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.

只需比较 invalidatepostInvalidate.

这篇关于postInvalidate() 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆