메뉴 건너뛰기

2015.07.16 19:35

ScrollView의 활용

조회 수 6530 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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.    @Override
10.    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.}

List of Articles
번호 제목 날짜 조회 수
257 버튼 이벤트 추가하기 file 2021.03.31 191
256 안드로이드 스튜디오 - 필수 재정의 함수 자동 코드 추가 file 2021.03.29 194
255 버튼 이벤트 file 2021.03.31 205
254 안드로이드 - 컨텍스트 메뉴(Context Menu) 사용 예제 file 2021.04.01 207
253 안드로이드 액티비티 세로고정 2021.09.14 207
252 안드로이드 - 인텐트(Intent)를 활용한 액티비티(Activity) 생성 및 실행하기 file 2021.03.31 213
251 안드로이드 - 액티비티(Activity)와 액티비티 생명 주기(Activity Life Cycle) file 2021.04.01 225
250 안드로이드 - setContentView()와 레이아웃 전개자(LayoutInflater) 2021.04.01 227
249 안드로이드 가상머신 실행 속도 빠르게 하기 file 2021.03.31 228
248 버튼 생성, 이벤트 처리 file 2021.03.31 236
247 안드로이드 - 스타일 리소스(Style Resource) 사용하기 <style> file 2021.03.31 238
246 안드로이드 - 랠러티브 레이아웃(Relative Layout) file 2021.03.29 239
245 This Handler class should be static or leaks might occur 시 해결법 2020.12.14 240
244 Fragment를 통한 하단탭 예제1 file 2020.12.14 242
243 App 실행 file 2021.03.31 244
242 안드로이드 - SQLiteDatabase 구현하기 file 2021.04.01 249
241 Virtual Device , 디자인 화면 file 2021.03.31 260
240 setContentView()와 레이아웃 전개자(LayoutInflater) 2021.03.31 266
239 안드로이드 - AsyncTask 구현 예제 file 2021.04.01 280
238 안드로이드 - 익명 클래스(Anonymous Class) 사용법 file 2021.03.31 281
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved