java ScrollView 内容更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11844935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ScrollView contents update
提问by FiniteRed
I have a programmatically generated ScrollView
with a TextView
inside of it. I wish to update the text in the TextView
from time to time and some have implemented a handler function to update the TextView
GUI element. This seems to call/work correctly.
我有一个以编程方式生成ScrollView
的TextView
内部。我希望TextView
不时更新文本,有些人已经实现了一个处理程序函数来更新TextView
GUI 元素。这似乎可以正常调用/工作。
However, currently the only way I have found to actuallyget the TextView
to show the appended information is to call:
不过,目前我发现的唯一方法实际上得到了TextView
显示附加信息是调用:
consoleText.append("New text to add to TextView");
// then:
myScrollView.removeView(myTextView);
myScrollView.addView(myTextView);
This is not particularity optimal and was wondering how else I can refresh the contents of the ScrollView
to show my newly added information...
这不是特别优化,我想知道我还能如何刷新内容ScrollView
以显示我新添加的信息......
Also:
还:
invalidate();
postvalidate();
Do not seem to do anything - the TextView
object has the new text in it (looking in debug) it's just not drawing it to the screen unless I call the add/remove function.
似乎没有做任何事情 -TextView
对象中有新文本(在调试中查看)它只是不将其绘制到屏幕上,除非我调用添加/删除函数。
Thanks for any information/help you can give
感谢您提供的任何信息/帮助
FR
阻燃剂
回答by Samuel
You should call invalidate()
and requestLayout()
on the TextView, and perhaps the ScrollView.
您应该在 TextView 和 ScrollView 上调用invalidate()
和requestLayout()
。