每秒设置textview的文本时,防止除textview之外的其他视图更新/重绘
我有一个稍微复杂的布局,包含几个自定义视图,每个视图计算它们需要多少空间等等。在这个布局的顶部,我有一个 TextView,它应该从 02:04:20 (hh:mm:ss) 开始倒计时,并每秒更新一次。
我的问题不是更新文本,问题是当我更新文本时,布局中的所有视图都会重新绘制。此外,我在此布局中使用画廊,因此在与画廊交互时当文本更新时,图库会立即切换到您选择的位置(即使您正在切换到图库中的新项目)。
那么..如何更新textview而不使其他视图重新绘制?
I've got a slightly complicated layout, containing several custom-views that each calculate how much space they need and whatnot. At the top of this layout, I've got a TextView which is supposed to count down from say.. 02:04:20 (hh:mm:ss), and update every second.
My problem is not updating the text, the problem is that when I DO update the text, ALL of the views in my layout gets re-drawn.. Also, I'm using a gallery in this layout, so when interacting with the gallery while the text is updated makes the gallery switch INSTANTLY to the place you've selected (even though you're in the middle of switching to a new item in the gallery).
So.. How to update the textview without making other views re-draw?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果视图的宽度是固定的并且视图的高度不会改变,那么 TextView 不会使 setText() 上的整个布局无效。将布局参数
android:layout_width
从"wrap_content"
更改为固定宽度,例如"fill_parent"
或"100sp"
。来源:
The TextView won't invalidate the entire layout on setText() if the view's width is fixed and the height of the view won't change. Change the layout parameter
android:layout_width
from"wrap_content"
to a fixed width like"fill_parent"
or"100sp"
.Source: