[안드로이드] ScrollView 사용법, 주의할 점 / 스크롤뷰 사용법, 주의한 점
[안드로이드] ScrollView 사용법, 주의할 점
화면에 들어가는 내용이 많다보면 스크롤뷰가 필요하다.
스크롤뷰를 사용할 때의 주의사항은
스크롤뷰를 하나의 자식만을 가진다는 것이다.
예를들어 버튼 5개를 스크롤 가능하게 한다면
버튼 5개를 리니어 레이아웃리나, 릴레이티브 레이아웃 등 레이아웃 하나에 묶은 다음에 스크롤뷰로 묶어야 한다.
[예제]
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="200dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn1"/>
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn2"/>
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn3"/>
<Button
android:id="@+id/btn14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn4"/>
<Button
android:id="@+id/btn15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn5"/>
</LinearLayout>
</ScrollView>