Study Record

[안드로이드] ScrollView 살펴보기 (+ NestedScrollView) 본문

안드로이드

[안드로이드] ScrollView 살펴보기 (+ NestedScrollView)

초코초코초코 2023. 6. 15. 15:44
728x90

😶 ScrollView

ScrollView 는 ViewGroup 내에 배치된 하위 요소들을 스크롤할 수 있는 ViewGroup 이다. ScrollView 에는 하나의 하위 ViewGroup 만 배치될 수 있다.

 

 

예시)

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:layout_weight="1"
            android:background="#FFF3F3F3"/>
        
        <View
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:layout_weight="1"
            android:background="#FF53F553"/>
            
        
        <View
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:layout_weight="1"
            android:background="#FF23F3F3"/>
            
    </LinearLayout>
</ScrollView>

 

 

스크롤바 없애기

android:scrollbars="none" 로 하면 스크롤바를 없앨 수 있다.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">
        
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

		...
    </LinearLayout>
</ScrollView>

 

 

😶 HorizontalScrollView

가로 방향으로 스크롤을 원한다면 HorizontalScrollView 를 사용한다.

 

 

😶 NestedScrollView

RecyclerView 혹은 ListView 가 포함된 ScrollView 를 사용하고 싶다면 NestedScrollView 를 사용하는 것이 좋다. ScrollView 의 하위 요소로 RecyclerView 혹은 ListView 가 포함되면 성능 면에서 좋지 않다.

 

ScrollView 에서 이름만 NestedScrollView 로 바꾸면 된다.

 

 

 

 

ScrollView  |  Android Developers

 

developer.android.com

 

728x90