메뉴 건너뛰기

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
번호 제목 날짜 조회 수
77 안드로이드 스튜디오 actionbar(액션바) 사라짐 file 2020.12.14 614
76 패키지명을 한꺼번에 변경하기 (Refactor) file 2020.12.14 296
75 하이브리드앱 기본 - WebView로 웹페이지 띄우기 file 2020.12.14 1025
74 ListView 리스트뷰 연습3 - 커스텀 리스트뷰 (Custom ListView) file 2020.12.14 906
73 초기화면 페이지를 만들어보자. splash 페이지 제작 file 2020.12.14 287
72 안드로이드 앱배포하기 apk 만들기 file 2020.12.14 326
71 안드로이드 입문 연습문제 3문항 - CheckBox, RadioButton, EditText, Spinner, 이벤트연습 file 2020.12.14 480
70 Apk manager 이용해 Decompile (디컴파일) 하기 file 2021.03.16 1624
69 안드로이드 arrayList 를 Json으로 변환 / jsonarry file 2021.03.29 326
68 안드로이드 unescape /escape [StringEscapeUtils로 해결] file 2021.03.29 344
67 안드로이드 스튜디오 - 싱글톤 패턴 (SingleTon Pattenr) 클래스 자동 생성 file 2021.03.29 621
66 안드로이드 스튜디오 - getter/setter 메소드 자동생성 file 2021.03.29 583
65 안드로이드 스튜디오 - 필수 재정의 함수 자동 코드 추가 file 2021.03.29 194
64 안드로이드 스튜디오 - 코드 자동 들여쓰기 file 2021.03.29 420
63 안드로이드 - 리니어 레이아웃 (Linear Layout) file 2021.03.29 319
62 안드로이드 - 랠러티브 레이아웃(Relative Layout) file 2021.03.29 239
61 안드로이드 - 프레임레이아웃 (FrameLayout) file 2021.03.29 517
60 안드로이드 - 에디트텍스트(EditText) 사용법 정리 file 2021.03.29 2760
59 버튼 생성, 이벤트 처리 file 2021.03.31 236
58 Java에서 XML 불러와서 동적 변화 주기 file 2021.03.31 288
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved