inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

레이아웃 꾸미기

댓글화면 레이아웃 디자인

해결된 질문

343

lalapys

작성한 질문수 7

0

안녕하세요 강의를 다 듣고 스스로 프로젝트를 개발하는중에 질문이 생겨서 질문드려요

 

 

저 댓글창부분을 android:layout_alignParentBottom="true"을 사용해서 하단에 고정시키려하는데 저 코드를 작성해도 고정이 안되는것같습니다. 리사이클러뷰를 적용하면 댓글창이 하단에 고정이 안되는것같습니다

그리고 댓글창을 제외하고 나머지부분을 스크롤뷰로 감싸서 댓글창 빼고 다 스크롤뷰로 스크롤될수있게 적용했는데 오류가 있는지 디자인 미리보기 화면이 아얘 사라져? 버립니다..

뭐가 문제인지 한번 봐주실수있을까요?

 

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

<layout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


    <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:layout_marginTop="25dp"
            android:orientation="horizontal">

        <ImageView
            android:id="@+id/backbutton"
            android:layout_marginStart="30dp"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/back_button"/>

        <ImageView
            android:layout_width="120dp"
            android:layout_height="25dp"
            android:layout_marginStart="100dp"
            android:src="@drawable/community_name"/>

        </LinearLayout>



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

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                app:srcCompat="@drawable/circle" />

            <TextView
                android:id="@+id/nickname1"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_weight="4"
                android:text="닉네임"
                android:fontFamily="@font/bmjua_ttf"
                android:textSize="20sp"
                android:textColor="@color/black"
                android:gravity="center_vertical"/>

            <ImageView
                android:id="@+id/threedot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:src="@drawable/threedot"/>


        </LinearLayout>



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


            <TextView
                android:id="@+id/title1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="제목"
                android:textSize="15sp"
                android:textStyle="bold"
                android:textColor="@color/black"
                android:layout_marginStart="30dp"/>


            <TextView
                android:id="@+id/content1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:layout_weight="1"
                android:text="내용"
                android:textSize="12sp" />

        </LinearLayout>



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

            <ImageView
                android:id="@+id/favorate1"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_weight="1"
                android:layout_marginStart="30dp"
                android:src="@drawable/heart1" />

            <TextView
                android:id="@+id/favorateText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="5dp"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:text="7"
                android:fontFamily="@font/bmjua_ttf"/>

            <ImageView
                android:id="@+id/comment1"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_weight="1"
                android:layout_marginStart="20dp"
                android:src="@drawable/comment1" />

            <TextView
                android:id="@+id/commentText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="5dp"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:text="5"
                android:fontFamily="@font/bmjua_ttf"/>


            <TextView
                android:id="@+id/time1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginStart="220dp"
                android:layout_gravity="center_vertical"
                android:fontFamily="@font/bmjua_ttf"
                android:textSize="10dp"
                android:text="2024.02.13" />

        </LinearLayout>
        



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:layout_marginTop="35dp"
            android:background="@color/bottomgray"/>


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/commentRV"
            android:layout_width="match_parent"
            android:layout_height="680dp"
            android:layout_marginTop="30dp"/>

        </ScrollView>



        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true">


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/button_radius_green_stroke">

            <EditText
                android:id="@+id/commentArea"
                android:hint="댓글을 작성해주세요"
                android:layout_marginLeft="10dp"
                android:layout_width="310dp"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"/>

            <Button
                android:id="@+id/commentBtn"
                android:layout_width="60dp"
                android:layout_height="45dp"
                android:layout_gravity="center_vertical"
                android:background="@drawable/button_radius_green"
                android:fontFamily="@font/bmjua_ttf"
                android:text="등록"
                android:textColor="@color/white"
                android:textSize="15dp"
                android:layout_marginEnd="8dp" />

        </LinearLayout>

        </RelativeLayout>




    </LinearLayout>



    </RelativeLayout>



</layout>

해당 레이아웃 전체코드입니다

android kotlin firebase

답변 1

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.
juwon님의 질문에 대해 답변드리겠습니다.

관련 코드를 살펴보니 ScrollView 내부에 RecyclerView를 배치하고 있으며, 댓글 입력창을 화면 하단에 고정하고자 하신 것으로 보입니다. ScrollView 안에 있는 LinearLayoutheightmatch_parent로 설정돼 있어서 스크롤 뷰 내용이 전체 화면을 차지하고 있습니다. 이로 인해 RecyclerView 다음에 오는 RelativeLayout이 화면 밖으로 밀려나갈 수 있습니다.

또한, ScrollView의 높이가 match_parent이고 RecyclerView의 높이 또한 특정 값으로 고정되어 있기 때문에 레이아웃이 의도한 대로 동작하지 않는 것으로 추정됩니다.

이 문제를 해결하려면 다음과 같은 방법을 시도해 볼 수 있습니다:

  1. LinearLayout (ScrollView 내부의 첫 번째 것) 의 layout_heightwrap_content로 변경해야합니다. 이렇게 하면 해당 LinearLayout이 내부 요소의 크기를 감싸고, ScrollView가 올바르게 스크롤될 수 있습니다.

  2. 하단 댓글 작성 부분이 항상 화면 하단에 고정되어야 하므로, ScrollViewRelativeLayout 내에서 above 속성을 사용하여 해당 댓글 작성 부분 바로 위에 위치하도록 할 수 있습니다.

다음은 수정된 레이아웃 일부입니다:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/commentInputArea"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ...>
        <!-- 댓글 입력창 관련 레이아웃 XML 코드 -->
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/commentInputArea">
        ...
    </ScrollView>

</RelativeLayout>

수정 후에도 문제가 계속된다면 레이아웃을 다시 빌드하거나 IDE를 재시작하여 미리보기를 새로고침 해보세요. 추가적으로, 레이아웃 미리보기에서 발생하는 문제일 수도 있으므로 실제 디바이스나 에뮬레이터에서 앱을 실행하여 정상적인 동작을 확인해볼 수 있습니다.

추가적인 도움이 필요하시면 깃허브 주소에 올라온 코드와 함께 문제를 재현하며 디버깅해보시길 추천드립니다.

이미지가 기본이미지인지 확인

0

131

1

NavController error 발생

0

140

1

fragment 생성하고 메인에서 불러왔는데 안뜹니다.

0

139

2

67강 댓글

0

95

2

7강 데이터바인딩 에러

0

113

2

Firebase 스토리지 유료화 문제

1

293

2

게시글 이미지가 파이어베이스에 저장되지 않습니다.

0

180

2

AVD 갤러리에 이미지 저장 안되는 문제

0

238

2

이미지 받아오는 방법?

0

202

2

회원탈퇴 기능을 추가하려고 합니다.

0

186

2

상태바 질문 드립니다.

0

110

1

섹션2 인트로 페이지 꾸미기 질문 드립니다.

0

108

1

게시판 글을 길게 쓸경우

0

123

2

로그인 로그아웃

0

175

2

갤럭시 연결시 게시판에 업로드한 사진이 보이지 않아요.

0

204

2

웹뷰 AVD 실행안됨

0

189

1

자막켜기가 안되요 ㅜ.ㅜ

1

185

1

리사이클러뷰, 그리드레이아웃 오류

0

185

2

리사이클러뷰 오류 해결 방법이 궁금합니다.

0

193

1

firebase 스마트폰으로 연결이 안되는데 원인이 있을까요

0

257

2

안드로이드 스튜디오 게시글 이미지 업로드 유무

0

217

1

firebase 설정 오류

0

302

2

홈 화면 커뮤니티

0

178

1

게시판 글 읽기

0

239

2