Android的无效()和postInvalidate()方法之间的区别是什么? [英] What is the difference between Android's invalidate() and postInvalidate() methods?

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

问题描述

()和 postInvalidate()方法的Andr​​oid的无效的区别是什么?什么时候每一个被调用?必须在方法调用只能在类延伸查看

What is the difference between Android's invalidate() and postInvalidate() methods? When does each one get called? Must the methods be called only in classes which extend View?

推荐答案

如果你想重新从 UI线程您可以致电画出你的看法无效()方法。

If you want to re draw your view from UI Thread you can call invalidate() method.

如果你想重新从非UI线程画出你的看法您可以致电 postInvalidate()方法。

If you want to re draw your view from Non UI Thread you can call postInvalidate() method.

这是从View类派生每个类都有的无效和postInvalidate方法。如果无效被调用它告诉,目前来看已经修改了系统,并应尽快重新绘制。由于这种方法只能从UIThread被称为另一种方法是在需要的时候你是不是在UIThread,仍然要通知你的观点已经被更改系统。所述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 shortly explained in the SDK documentation:

点击此处

更新:

有从其它线程使用时,postInvalidate(如不具有UI更新的右走),这将是更有效地出现了一些问题:

There are some problems that arise when using postInvalidate from other threads (like not having the UI updated right-away), this will be more efficient:

runOnUiThread(new Runnable() {
    public void run() {
    myImageView.setImageBitmap(image);
    imageView.invalidate();
    }
});

这篇关于Android的无效()和postInvalidate()方法之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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