• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    해결됨

댓글화면 레이아웃 디자인

24.02.22 15:18 작성 24.02.25 00:24 수정 조회수 91

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>

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

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.02.24

안녕하세요, 인프런 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를 재시작하여 미리보기를 새로고침 해보세요. 추가적으로, 레이아웃 미리보기에서 발생하는 문제일 수도 있으므로 실제 디바이스나 에뮬레이터에서 앱을 실행하여 정상적인 동작을 확인해볼 수 있습니다.

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