如何在视图更改时重绘 Android Gallery?
我正在修改 Activity
来实现 onConfigurationChanged(...)
,它包含一个扩展的 Gallery
,其成员使用其 手动调整大小来自
。Gallery
适配器的 LayoutParams
不幸的是,Gallery
最初显示错误:扩展的View
填满了整个屏幕。不过,一旦选择了另一个项目,View
就会以正确的大小显示。
作为实验,我尝试冻结 Gallery#onConfigurationChanged(...)
方法中所选 View
的尺寸,并且发生了相同的行为,表明 View
已更新,但图库
未显示更改。
我还尝试从 Activity#onConfigurationChanged(...)Gallery
上调用 invalidate()
和 postInvalidate()
代码>.没有什么。
如何强制 Gallery
使用 View
的正确尺寸重新绘制?
I am modifying an Activity
to implement onConfigurationChanged(...)
and it contains a extended Gallery
whose members are sized manually using their LayoutParams
from the Gallery
's adapter.
Unfortunately the Gallery
initially displays wrong: the extended View
fills the whole screen. As soon as another item is selected, though, the View
displays with the correct size.
As an experiment, I tried freezing the dimensions of the selected View
from the Gallery#onConfigurationChanged(...)
method and the same behaviour occurred, suggesting the View
has been updated, but the Gallery
isn't showing the change.
I also tried calling both invalidate()
and postInvalidate()
on the Gallery
from Activity#onConfigurationChanged(...)
. Nothing.
How can I force the Gallery
to redraw with the correct dimensions for the View
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在图库适配器上调用
notifyDataSetChanged()
应该可以完成这项工作。如果没有,则可能是您的代码某处有问题。
Calling
notifyDataSetChanged()
on your gallery adapter should do the job.If it does not, it may be something wrong with your codes somewhere.