invalidate和postInvalidate的区别
至于什么invalidate,invalidate是做什么用的。
这个问题老外是这么回答的:
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.
只要是view的子类,都会从view中继承invalidate和postInvalidate这两个方法。
当invalidate方法被调用的时候,就是在告诉系统,当前的view发生改变,应该尽可能快的来进行重绘。
这个方法仅能在UI线程中被调用。如果想要在工作线程中进行刷新界面,那么其他的方法将会被调用,这个方法就是postInvalidate方法。
这个方法将会发送消息到主线程,当主线程的消息队列轮询到当前消息的时候,这个方法会被调用。
但是需要注意的是,刷新界面并不能保证马上刷新。只是尽可能快的进行刷新。尤其是在postInvalidate方法中,这种情况会出现。
至于可能会有人问postInvalidate是怎么保证线程安全的。那么我们需要看一下postInvalidate的源码:
public void postInvalidate() {
postInvalidateDelayed(0);
}
public void postInvalidateDelayed(long delayMilliseconds) {
// We try only with the AttachInfo because there's no point in invalidating
// if we are not attached to our window
if (mAttachInfo != null) {
Message msg = Message.obtain();
msg.what = AttachInfo.INVALIDATE_MSG;
msg.obj = this;
mAttachInfo.mHandler.sendMessageDelayed(msg,
Android 界面刷新的方法 Android 提供了 Invalidate 方法实现界面刷新,但是 Invalidate 不能直接在线程中调用,因为 他是违背了单线程模型: Android UI 操作并不是...
利用Handler实现界面刷新_IT/计算机_专业资料。利用Handler实现界面刷新在android 中,比如在一个 activity 里面创建了一个 View 用于显示下载进度,由于进度一直 再变...
Android Service通知Activity更新界面的方法研究_IT/计算机_专业资料。Android ... Android界面刷新的方法 2页 免费 android中activity_inte... 8页 免费 [...
jquery mobile界面数据刷新_互联网_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 jquery mobile界面数据刷新_互联网_IT/计算机_专业资料。jquery mobile...
[Android开发学习29]界面控件之列表控件(ListView)--显示图片和文本_计算机软件及应用_IT/计算机_专业资料。[Android开发学习29]界面控件之列表控件(ListView)--...
Android的界面设计规范_计算机软件及应用_IT/计算机_专业资料。Android UI 界面...要使用预定义的说明,如“刷新”和“共享” 尺寸和比例 电话的动作条图标应该是...
Android 类ListView下拉刷新控件实现_互联网_IT/计算机_专业资料。Android 类...此刻又会遇到一个问题:我在界面执行下拉时,应用如何分辨 itiw iw 我是执行的R...
【转】使用HTML来生产Android界面_IT/计算机_专业资料。【转】使用 HTML 来...()">刷新 function show(jsondata){ var jsonobjs = eval_r(jsondata); var...
安卓系统Android应用程序开发PPT教材_第5章Android用户界面(29)_通信/电子_科技_PPT专区。安卓系统Android应用程序开发PPT教材_第5章Android用户界面(29)...
android.app.Activity; import android.app.AlertDialog; import android.content.... "分享页面", "退出", "夜间模式", "刷新", "更多" }; /** 菜单图片...
热门文档