Android中实现view的更新UI有两组方法
来源:互联网 发布:misumi选型软件2015 编辑:程序博客网 时间:2024/05/17 03:59
一组是invalidate,另一组是postInvalidate,其中前者是在UI线程自身中使用,而后者在非UI线程中使用。 SDK中说: public void invalidate() public void postInvalidate () google的文档的说明实在是简单,往往看了开发中都会遇到这两个问题: 最后,通过查文档,上网查询才知道,invalidate和postInvalidate方法需要使用Android提供的handler,才能实现重绘 ,而在文档的说明中却只字不提,真是简单啊。具体是在需要重绘的地方调用handler的sendMessage方法发送消息,紧接着会os会触发 handler中的handlerMessage方法,在handlerMessage方法中再调用view的invalidate或者 postInvalidate方法就能实现重绘。 class CustomizeView extends WhichView {
Invalidate the whole view. If the view is visible, onDraw(Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.
1. 没有任何异常,view没能刷新。
2. Android应用异常终止,打开logcat会看到这样的异常信息, Only the original thread that created a view hierarchy can touch its views。
public CustomizeView(Context context) {
super(context);
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
// delay some minutes you desire.
/*try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}*/
handler.post(new Runnable() {
public void run() {
concreteUpdateUI();
invalidate();
}
});
}
}).start();
}
protected void concreteUpdateUI() {
// Add concrete movement for UI updates.
// ...
}
}
- Android中实现view的更新UI有两组方法
- android中实现view的更新UI有两组方法的问题
- Android中实现view的更新有两组方法
- android中实现view的更新有两组方法
- Android中实现view的更新有两组方法
- android中接口实现更新UI方法
- Android中更新UI的方法
- android中更新UI的方法
- Android中更新UI的方法
- Android在非UI线程中更新UI的方法
- Android显示系统之View与SurfaceView更新屏幕的区别.对于View.则是在UI主线程中更新画面.SurfaceView更新屏幕,是在非UI线程(主线程)中实现SurfaceHolde
- Android中子线程中更新UI的N中方法
- Android更新UI的方法
- android更新UI的方法
- Android更新ui的方法
- Android新线程中更新主线程UI中的View方法汇总
- Android新线程中更新主线程UI中的View方法汇总
- android子线程中更新UI的方法
- sql2005存储过程分页代码。
- C2812 CMD文件的配置理解
- ubuntu面板恢复
- java断点续传
- 工厂模式
- Android中实现view的更新UI有两组方法
- 那位高手给指导一下??
- linux下配置tomcat 虚拟主机的方法
- Qt中的日期转换小记
- 有时心情总是那么的沉闷
- (一)再见了,我亲密的战友们 人一口福
- 泛型
- Android系统开发编译环境配置
- Directshow的视频捕捉