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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:37:16  来源:igfitidea点击:

ScrollView contents update

javaandroidtextviewscrollviewhandler

提问by FiniteRed

I have a programmatically generated ScrollViewwith a TextViewinside of it. I wish to update the text in the TextViewfrom time to time and some have implemented a handler function to update the TextViewGUI element. This seems to call/work correctly.

我有一个以编程方式生成ScrollViewTextView内部。我希望TextView不时更新文本,有些人已经实现了一个处理程序函数来更新TextViewGUI 元素。这似乎可以正常调用/工作。

However, currently the only way I have found to actuallyget the TextViewto 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 ScrollViewto show my newly added information...

这不是特别优化,我想知道我还能如何刷新内容ScrollView以显示我新添加的信息......

Also:

还:

invalidate();
postvalidate();

Do not seem to do anything - the TextViewobject 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()