[Android Studio] ScrollView

Minjun Kim·2023년 8월 15일
0

Android

목록 보기
6/47
post-thumbnail

ScrollView 사용법

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"		// 자식 View의 크기만큼 ScrollView 크기 확장
        android:scrollbars="none">		// 스크롤바 숨기기

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </LinearLayout>
        
    </ScrollView>

주의점

  1. 스크롤 뷰는 단 1개의 자식만을 가진다.

  2. 스크롤 뷰는 자식의 크기 만큼 늘어난다.

  3. 보이지 않는 부분의 뷰까지 미리 생성하므로 메모리 사용량이 늘어난다.
    -> AdapterView로 극복 검토

[참고]
자식 View의 height에 fill_parent 속성을 주어도 적용되지 않는 이유

  • 스크롤 뷰는 자식 View의 크기만큼 늘어남 -> 자식 View는 부모 View의 크기에 맞춤
    = 적용 안됨

🔎 [참고 사이트]

arabiannight.tistory


ConstraintLayout을 자식 View로 사용하는 경우

  • ScrollView 대신 NestedScrollView 사용 권장
<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.core.widget.NestedScrollView>

🔎 [참고 사이트]

m-falcon.tistory

profile
응애 나 아기 뉴비

0개의 댓글