본문 바로가기
Programming/Android

ScrollView 아래에 버튼 두기

by 유주원 2015. 2. 7.

앱 화면에 ScrollView를 두고 그 아래에 확인 버튼을 두려고 하는데 자꾸 확인 버튼을 ScrollView가 뒤덮는 상황이 발생한다.


기존에 구현한 코드는 아래와 같다.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical" android:layout_height="match_parent"

    android:layout_width="match_parent">

    <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"

            android:background="#dadada">

            <TextView

                android:layout_width="wrap_content"

                 android:id="@+id/cnf_appname"

                 android:layout_height="wrap_content"

                 android:textColor="@android:color/black"

                 android:textSize="18dip" />

        </LinearLayout>

    </ScrollView>

    <Button 

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@+id/confirm_button" />

</LinearLayout>


해결 방법은 의외로 간단했다.

ScrollView에서 android:layout_weight="1" 로 설정해주면 아래 Button이 보이게 된다.

layout_weight=1로 설정을 하게 되면 우선 Button의 height가 wrap_content이기 때문에 Button이 필요로 하는 영역을

제외한 나머지 모든 부분을 ScrollView가 차지하겠다는 뜻이 된다.


만약 이 설정을 하지 않는다면 ScrollView의 wrap_content를 우선 처리하기 때문에 Button 영역이 ScrollView 영역에

뒤덮여서 안보이게 된다.