()和 postInvalidate()
方法的Android的无效的区别是什么?什么时候每一个被调用?必须在方法调用只能在类延伸
查看
?
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();
}
});