有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在运行时向ScrollView添加文本?

我想知道如何在运行时向滚动视图添加文本。我在安卓工作室工作。我有一个正在读取的文件,并已将文本行放入StringBuilder缓冲区对象中

现在如何在滚动视图中显示文本?我需要使用吗。AddView


共 (2) 个答案

  1. # 1 楼答案

    Scrollview是一个单元素容器,这意味着其中应该只有一个元素

    A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

    所以你应该在你的ScrollView中添加一个LinearLayout,然后添加视图

  2. # 2 楼答案

    在ScrollView中添加TexView:

    TextView tv = new TextView(this);
    tv.setText("Your string");
    
    scrollView.addView(tv);