Android 滚动视图-文本视图-滚动的最佳技术是什么

Android 滚动视图-文本视图-滚动的最佳技术是什么,android,scroll,textview,scrollview,Android,Scroll,Textview,Scrollview,我的应用程序正在记录一个文本信息,我使用的技术是基于一个文本视图,嵌入在一个滚动视图中,包含完整的字符串 这种方法的真正缺点是字符串随着时间的推移会变得非常大,如果不是因为系统内存不足而崩溃的话,您所能体验到的最好情况就是性能降低 我还可以使用哪些其他技术 下面是我想出的代码: public class MainActivity extends AppCompatActivity { boolean run = true; String str = "", t; int

我的应用程序正在记录一个文本信息,我使用的技术是基于一个文本视图,嵌入在一个滚动视图中,包含完整的字符串

这种方法的真正缺点是字符串随着时间的推移会变得非常大,如果不是因为系统内存不足而崩溃的话,您所能体验到的最好情况就是性能降低

我还可以使用哪些其他技术

下面是我想出的代码:

public class MainActivity extends AppCompatActivity {
    boolean run = true;
    String str = "", t;
    int i = 0;
    TextView txt;
    ScrollView sv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txt = (TextView) findViewById(R.id.txt);
        Button btn = (Button) findViewById(R.id.btn);
        sv = (ScrollView) findViewById(R.id.sv);

        t = "this is the log for monday the 24th of july 2017 - number ";


        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                start();
            }
        });

    }

    private void start(){
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    public void run() {
                        i++;
                        str = str + t + i + "\n";
                        txt.setText(str);
                        sv.fullScroll(ScrollView.FOCUS_DOWN);
                    }
                });
            }
        }, 0, 100);
    }
}
布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.narb.log.MainActivity">

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Start"
        />

    <ScrollView
        android:id="@+id/sv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_below="@id/btn"
        >

        <TextView
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="This is the log number"
            android:layout_margin="15dp"
            />
    </ScrollView>
</RelativeLayout>
而不是str=str+t+i+\n;和txt.setTextstr; 尝试使用str=t+i+\n;和txt.setTexttxt.getText+str; 或者您也可以简单地使用txt.setTexttxt.getText+t+i+\n