TextView를 사용하다보면 내용이 너무 길어지는데, 이 때 스크롤을 하고 싶을 때가 있습니다.
이럴때 ScrollView를 사용하면 간단하게 해결이 됩니다.
너무 간단해서 layout의 xml 부분만 있으면 될 것 같습니다. 테스트로 사용한 main.xml 입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dip">
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"
/>
</ScrollView>
</LinearLayout>
테스트를 위해 Activity에 다음과 같은 코드를 넣었습니다.
01.package Scroll.View.Example;02. 03.import android.app.Activity;04.import android.os.Bundle;05.import android.widget.TextView;06. 07.public class ScrollViewExample extends Activity {08. /** Called when the activity is first created. */09. @Override10. public void onCreate(Bundle savedInstanceState) {11. super.onCreate(savedInstanceState);12. setContentView(R.layout.main);13. 14. String strText = "";15. for (int i=0; i<100; i++)16. {17. strText = strText + "텍스트 라인 : " + i + "\n";18. }19. 20. TextView tv = (TextView)findViewById(R.id.textView);21. 22. tv.setText(strText);23. }24.}