Android App Coding
스크롤뷰 Scrollview
IT Knowledge Share
2021. 7. 7. 11:47
반응형

스크롤뷰는 스크롤 기능이 적용된 뷰를 만들어냅니다.
스크롤뷰에서 가장 중요한 부분은, 자식/하위 뷰로 단 한 개만 가질 수 있다는 부분입니다.
아래 코드를 통해서 좀 더 살펴 봅니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingTop="100dp"
android:text="내려주세요"
android:textColor="@color/black"
android:textSize="50dp"
android:background="#3F51B5" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingTop="100dp"
android:text="내려주세요"
android:textColor="@color/black"
android:textSize="50dp"
android:background="#E91E63" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingTop="100dp"
android:text="내려주세요"
android:textColor="@color/black"
android:textSize="50dp"
android:background="#FFEB3B" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingTop="100dp"
android:text="마지막부분"
android:textColor="@color/black"
android:textSize="50dp"
android:background="#4CAF50" />
</LinearLayout>
</ScrollView>
</LinearLayout>
스크롤뷰를 사용할 때, 자주 사용되는 속성을 알아 봅시다.
android:layout_height="match_parent" => 스크롤뷰의 높이를 500dp 이런식으로 설정하면, 설정한 값 내에서 스크롤바가 움직이게 됩니다.
android:fillViewport="true" => 해당 값은 항상 true입니다. 지정하지 않으면, 기능상에 장애가 일어날 수 있습니다.
android:scrollbars="none" => none으로 설정하면, 스크롤바 막대가 보이지 않습니다. 속성을 아예 부여하지 않으면, 스크롤바 막대가 보이게 됩니다.
반응형