您的位置:首页 > 移动开发 > Android开发

Android中postinvalidate和validate的区别

2015-06-05 00:59 507 查看
1. 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 event loop on the UIThread as soon as possible. It is also briefly
explained in the SDK documentation.

2. 

By this method (
postInvalidate()
),
you can invalidate a 
View
 from
non-UI threads. To invalidate a 
View
 from
UI-thread use 
invalidate()
 method.

The invalidation means, that the 
View.onDraw(Canvas)
 method
will we called at some point in the future (not immediately) to redraw whole 
View
 (if
the 
View
 is
visible).

Android is redrawing 
View
s
automaticly, but sometimes is necessary to tell: "Hey, this 
View
 has
been changed, redraw it as fast as possible."

More at:

http://developer.android.com/guide/topics/ui/how-android-draws.html

http://developer.android.com/reference/android/view/View.html#invalidate%28%29
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: