강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

ancan Eil님의 프로필 이미지
ancan Eil

작성한 질문수

[초급편] 안드로이드 커뮤니티 앱 만들기(Android Kotlin)

글작성 엑티비티에서 키보드 사용시 스크롤로 화면을 올리는것이 되지 않습니다

작성

·

478

0

강의를 따라하면서 게시글을 작성하는 엑티비티를 따라서 완료 하였습니다.

키보드 사용시 화면이 올라가게 하는것을 따라 만들려고 하였으나 올라가지 않습니다.

데이터 바인딩이 아니고 뷰바인딩을 사용하여 layout 으로 감싸지 않았고 문제를 해결해보기위해 인터넷을 뒤지며 xml 을 수정하여 강의와 좀 차이가 있습니다.

xml 을 어떻게 수정해야 스크롤이 작동 할까요?

 

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
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=".board.BoardWriteActivity">

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

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="글쓰기 페이지"
android:textColor="@color/black"
android:textSize="30dp" />
</LinearLayout>

<EditText
android:id="@+id/TitleArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_margin="20dp"
android:background="#000000" />

<EditText
android:id="@+id/ContentsArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="내용을 적어주세요" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_margin="20dp"
android:background="#000000" />

<ImageView
android:id="@+id/ImageBtn"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:src="@drawable/plus" />

<Button
android:id="@+id/WriteButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:backgroundTint="@color/mainblue"
android:text="입력"
android:textColor="@color/black"
android:textSize="20dp" />

</LinearLayout>

</LinearLayout>

</ScrollView>

답변 2

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

또 문의사항 있으시면 알려주세요 :)

ancan Eil님의 프로필 이미지
ancan Eil
질문자

강의에서는 EditText 를 따로 추가 안하고 키보드만 띄어져도 자동으로 스크롤이 되었는데 그렇게는 안되는건가요?

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

강의 어느부분을 수강중이신지 알려주시면 살펴보겠습니다~

ancan Eil님의 프로필 이미지
ancan Eil
질문자

질문당시에는 게시글 업로드 강의를 보고 있었습니다. 섹션6의 2번쨰 강의 입니다.

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

이 부분을 수강중이신게 맞으실까요?

여기 보시면, 전체 세로 길이가 깁니다.

 

예를 들면 전체 디바이스 길이가 1000

내용물 길이가 600

키보드 창 길이가 500

 

그러니깐 총 내용물 길이가 1100이 되어, 디바이스보다 길게 되어 스크롤이 되는 형태입니다.

 

그런데, 작성해주신 부분의 내용물이 짧기 때문에, 전체를 스크롤 할 일이 없어서 스크롤이 되지 않는 형태에요~

 

 혹시 이해가 어려우시면 한번 더 문의주세요 :)

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

안녕하세요! 

 

ScrollView안의 영역의 전체 화면보다 작기 때문입니다.

 

예를 들면 전체 화면이 1000dp 인데, LinearLayout의 크기가 500이면, 전체화면보다 작기 때문에 스크롤이 내려갈 영역이 없겠죠?

 

아래와 같은 코드로 테스트해보시면 스크롤이 내려가는 것을 보실 수 있습니다.

 

내용물을 채워서 제가 세로 길이를 늘렸어요

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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=".board.BoardWriteActivity">

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

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="글쓰기 페이지"
android:textColor="@color/black"
android:textSize="30dp" />
</LinearLayout>

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />
<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="제목을 적어주세요" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_margin="20dp"
android:background="#000000" />

<EditText
android:id="@+id/ContentsArea"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="#00ff0000"
android:gravity="center"
android:hint="내용을 적어주세요" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_margin="20dp"
android:background="#000000" />



</LinearLayout>

</LinearLayout>

</ScrollView>
ancan Eil님의 프로필 이미지
ancan Eil

작성한 질문수

질문하기