안드로이드 스튜디오

[안드로이드 스튜디오] 원하는 부분만 스크롤 기능 주기 ScrollView

yangcotton 2023. 8. 30. 15:21

파란색으로 정한 칸 내에서만 스크롤을 적용하고 싶고

나머지는 고정하고싶다!

 

실제 스크롤을 하면 이렇게 리스트만 올라간다.

 

전체 소스를 보고싶은경우

https://yangcottondev.tistory.com/36

 

[안드로이드 스튜디오] GCS 앱 만들기 - 전체소스

MainActivity.java package com.example.gcs; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.Layo

yangcottondev.tistory.com

 

 

ScrollView를 사용하면 된다.

 

ScrollView를 사용할땐 LinearLayout 로 감싼 부분만 스크롤을 사용할 수 있다 ! 필수 ~

 

코드로 보려면 아래 더보기 클릭!

더보기
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="600dp">

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

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

                <TextView
                    android:id="@+id/txtItem1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="7dp"
                    android:text="눈뜨기 기능 "
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar1"
                    android:layout_gravity="center_horizontal"
                    android:text="눈뜨기 기능 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar1"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem1"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

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


                <TextView
                    android:id="@+id/txtItem2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10dp"
                    android:text="언어기능"
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar2"
                    android:layout_gravity="center_horizontal"
                    android:text="언어기능 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar2"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem2"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/txtItem3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="7dp"
                    android:text="운동기능 "
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar3"
                    android:layout_gravity="center_horizontal"
                    android:text="운동 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar3"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem3"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

            <TextView
                android:id="@+id/delete1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:layout_marginTop="20dp"
                android:text="1.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="2.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="3.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="4.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="5.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="6.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="7.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="8.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="9.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="10.스크롤 및 목록삭제 확인 리스트"
                android:textSize="27sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="11.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="12.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete13"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="13.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete14"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="14.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete15"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="15.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="버튼"
        />
    </LinearLayout >

</LinearLayout >

스크롤을 보려고 소스가 길다.. ㅋㅋ

 

LinearLayout으로 파트를 나눠주고 

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="600dp"

높이를 지정해주어 사용할 파트를 정한다.

 

xml에서만 하면되서 편하다