ScrollView는 하나의뷰만 감쌀수있다는 특징이 있다!!
그렇기때문에 여러뷰를 ScrollView로 묶어주고싶으면 일단 그 뷰들을 LinearLayout이나 ConstraintLayout 등으로 묶어준뒤 ScrollView로 묶어줘야한다
<ScrollView>
<LinearLayout>
<TextView/>
<ImageView/>
<TextView/>
</LinearLayout>
</ScrollView>
이런식으로 묶어줘야한다
아래는 ScrollView를 사용한 예제이다
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".recipebook.RecipebookWriteActivity">
<ImageView
android:id="@+id/close2"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/no_button" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
app:layout_constraintBottom_toBottomOf="@+id/close2"
app:layout_constraintStart_toEndOf="@+id/close2"
app:layout_constraintTop_toTopOf="@+id/close2"
app:srcCompat="@drawable/recipewrite_title" />
<Button
android:id="@+id/recipe_uploadbutton"
android:layout_width="70dp"
android:layout_height="40dp"
android:background="@drawable/button_radius_green"
android:fontFamily="@font/bmjua_ttf"
android:text="업로드"
android:textColor="@color/white"
android:textSize="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toBottomOf="@+id/imageView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView6" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="80dp"
android:padding="15dp"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/bmjua_ttf"
android:text="레시피 이름"
android:textColor="@color/black"
android:textSize="18sp" />
<EditText
android:id="@+id/titleET"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/bmjua_ttf"
android:textSize="17sp"
android:hint="레시피 이름을 작성해주세요"
android:padding="10dp"
android:background="@drawable/button_radius_gray_stroke" />
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/bmjua_ttf"
android:layout_marginTop="30dp"
android:text="레시피 재료"
android:textColor="@color/black"
android:textSize="18sp" />
<EditText
android:id="@+id/contentET"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/bmjua_ttf"
android:textSize="17sp"
android:hint="ex) 스테이크, 고구마, 소금,,"
android:padding="10dp"
android:background="@drawable/button_radius_gray_stroke" />
<TextView
android:id="@+id/recipeimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/bmjua_ttf"
android:layout_marginTop="30dp"
android:text="요리사진"
android:textColor="@color/black"
android:textSize="18sp" />
<ImageView
android:id="@+id/recipeimage_upload"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="20dp"
android:src="@drawable/recipe_image"/>
<TextView
android:id="@+id/content1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/bmjua_ttf"
android:layout_marginTop="30dp"
android:text="레시피 작성"
android:textColor="@color/black"
android:textSize="18sp" />
<EditText
android:id="@+id/contentET1"
android:layout_width="370dp"
android:layout_height="400dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/bmjua_ttf"
android:textSize="17sp"
android:hint="레시피 순서에 맞춰 레시피를 작성해주세요"
android:gravity="top"
android:padding="10dp"
android:background="@drawable/button_radius_gray_stroke"
app:layout_constraintEnd_toEndOf="@+id/titleET"
app:layout_constraintStart_toStartOf="@+id/titleET"
app:layout_constraintTop_toBottomOf="@+id/content" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
'개발 노트 > Kotlin' 카테고리의 다른 글
[kotlin]No layout manager attached; skipping layout 오류 (0) | 2024.02.25 |
---|---|
[Kotlin] LinerLayout 왼쪽 정렬, 오른쪽 정렬 (0) | 2024.02.22 |
[kotlin] lateinit property has not been initialized 에러 (0) | 2024.02.21 |
Custom Dialog 만들기 (1) | 2024.02.21 |
RecyclerView 클릭 이벤트 처리 (0) | 2024.02.21 |