Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 정처기
- 테스팅원리
- 컴퓨터과학개론
- kiss원칙
- 방통대
- 소프트웨어공학
- 컴퓨터과학과
- 정보처리산업기사
- 균일비용탐색
- 린소프트웨어개발론
- 정보처리기사
- 결함테스팅
- 정의
- 모바일앱프로그래밍
- 소프트웨어테스트
- 프로그래밍
- 프로그래밍패러다임
- A* 알고리즘
- 언덕오르기탐색
- 한국방송통신대학교
- 공부하는직장인
- 결함테스팅검증테스팅차이
- 수제비
- 개발자
- 비전공자
- 정처기준비
- 프로그래밍언어패러다임
- 검증테스팅
- 시험공부
- 린개발론
Archives
- Today
- Total
우와테크
android 안드로이드 ScrollView 사용법 본문
화면가득 view를 만들고 ScrollView를 사용하지 않으면 스크롤이 되지않는다.
당연한 사실인데.. 인지하지 못했다.
ListView나 RecyclerView처럼 지원해주는 줄 알았다.
ScrollView는 간단하다.
LinearLayout처럼 ScrollView안에 들어갈 구성요소들을 감싸주면 된다.
여기서 주의사항은 두가지!
ScrollView 안에는 반드시 하나의 레이아웃을 둬야 한다.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom"
android:text="분류"/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:spinnerMode="dialog"/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom"
android:text="비고"/>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:theme="@style/EditTextStyle"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
이와 같이 많은 레이아웃을 정의하더라도 LinearLayout으로 감싸면 한개의 레이아웃이 된다.
이 코드는 가능 하다.
하지만..
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom"
android:text="분류"/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:spinnerMode="dialog"/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom"
android:text="비고"/>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:theme="@style/EditTextStyle"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
이와 같이 FrameLayout과 LinearLayout 이 두개의 레이아웃으로 두면 오류가 난다.
ScrollView can host only one direct child Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
처음처럼 하나의 레이아웃으로 만들면 오류 없이 잘 작동된다.
ScrollView 상단 코드는 보이지만 ScrollView 하단 코드는 보이지 않는다.
간단하다.
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="추가"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
.....
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="저장"/>
이 코드를 실행했을 때 추가 버튼은 보이지만 저장 버튼은 보이지 않는다.
아무런 오류가 찍히지 않고 보이지 않기 때문에 원인을 찾기가 어렵다.
ScrollView 밖에 레이아웃을 만들고자 한다면 반드시 상단에 두자.