立即应用 ui 更改 [英] apply ui changes immediately

查看:24
本文介绍了立即应用 ui 更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android 上编写一些 ui 屏幕.有时我需要立即查看 ui 更改,但是可以在下一个 ui 线程请求中看到这些更改.因此,例如,如果我删除屏幕上的一个视图并以编程方式添加另一个视图,然后更改整个视图(使用 viewAnimator),则可以观察到删除视图,但无法观察到新视图.我确定添加了新视图,因为当我返回第一页时,屏幕上会显示新视图.

I m coding some ui screens on android. sometime I need to see ui changes immediately, but that changes can be seen on next ui thread request. so, for example if I remove a view on screen and add another view programmatically, then change whole view (with viewAnimator), removing view can be observed, but new view can not be observed. I m sure new view is added, because when I go back to first page, new view is on screen.

我应该调用哪个函数在屏幕上添加或删除一些视图以立即查看其效果?

which function should I call add or remove some view on screen to see its effect immediatlety ?

我尝试了 invalidate(),但它不适用于我的情况

I tried invalidate(), but it doesnt work for my case

推荐答案

invalidate() 在没有可绘制(甚至透明)或没有子项的视图上不被调用.您必须在 setBackgroundDrawable(Color.Transparent) 到所有这些或在开发时添加一个虚拟子视图来观察变化.

invalidate() on views that have no drawable (even transparen) or no children is not called. You have to at setBackgroundDrawable(Color.Transparent) to all of them or add a dummy child view at development to observe changes.

另请注意,在 Android 3 + 上,渲染系统已更改.当您使父项无效时,子项并不总是无效.如果您想要与较低版本相同的行为,您应该手动使整个树无效

Also notice that at Android 3 + the rendering system has changed. When you invalidate parent the children are not always invalidated. You should invalidate the whole tree manually if you want the same beahvior as lower versions

这篇关于立即应用 ui 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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