강의

멘토링

커뮤니티

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

Keys님의 프로필 이미지
Keys

작성한 질문수

[왕초보편] 앱 8개를 만들면서 배우는 안드로이드 코틀린(Android Kotlin)

"프롤로그에서 콘텐츠가 허용되지 않습니다." 오류

해결된 질문

작성

·

50

0

선생님, 강의 잘 듣고 있습니다. 그런데 영탁 등등의 노래 리사이클러뷰 앱을 만들 때, 다음까지는 잘 됩니다.

그런데 이후 <TextView> 부분에 background를 첨가하거나 텍스트를 바꾸기만 해도 계속 위의 제목에서 보인 오류가 뜨고, 이후 다른 fragment에서도 마찬가지 오류가 뜹니다.

왜 그런 것이며, 어떻게 해결해야 할지요? 현재 최신 버전이 Otter를 사용하고 있습니다.

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

    <TextView
        android:text="영탁 노래 리스트"
        android:textColor="@color/black"
        android:gravity="center"
        android:layout_margin="10dp"
        android:textSize="30sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/singRV"
        android:layout_marginTop="50dp"
        android:layout_marginBottom="80dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        app:layout_constraintBottom_toBottomOf="parent">
        
        <ImageView
            android:id="@+id/image1"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <ImageView
            android:id="@+id/image2"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <ImageView
            android:id="@+id/image3"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>


    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout> 

답변 3

1

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

확인해봤습니다.

ConstraintLayout에서 제약조건(수평/수직) 모두 제약조건이 있어야합니다

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_constraintTop_toTopOf="parent" />

 

layout_constraintTop_toTopOf 수직 조건이 있지만 수평 관련된 조건이 없습니다.

아래와 같이 변경해보시겠어요?

 

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

    <!-- 제목 TextView: ID 추가 및 좌우 제약 조건 추가 -->
    <TextView
        android:id="@+id/titleText"
        android:text="영탁 노래 리스트"
        android:textColor="@color/black"
        android:gravity="center"
        android:layout_margin="10dp"
        android:textSize="30sp"
        android:layout_width="0dp"
        android:background="@color/black"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <!-- RecyclerView: 제약 조건 추가 -->
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/singRV"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/titleText"
        app:layout_constraintBottom_toTopOf="@id/bottomLayout"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <!-- LinearLayout: ID 추가 및 좌우 제약 조건 추가 -->
    <LinearLayout
        android:id="@+id/bottomLayout"
        android:layout_width="0dp"
        android:layout_height="80dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <ImageView
            android:id="@+id/image1"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo1"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>

        <ImageView
            android:id="@+id/image2"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo2"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>

        <ImageView
            android:id="@+id/image3"
            android:scaleType="fitXY"
            android:layout_weight="1"
            android:src="@drawable/photo3"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Keys님의 프로필 이미지
Keys
질문자

예, 말씀해 주신 대로 하여 잘 해결되었습니다.

constraintLayout의 경우 제약 조건 설정이 매우 중요하다는 것을 새로 알게 되었습니다.

감사합니다.

0

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

안녕하세요~
Activity와 fragment를 포함한 모든 코드를 공유해주시면 저도 살펴보겠습니다!

압축파일 형태로 구글 드라이브같은 곳에 업로드 후 다운받을 수 있는 링크를 공유주셔도 되고

코드 전체를 복사 붙여넣기 해주셔도 좋습니다!

Keys님의 프로필 이미지
Keys
질문자

빠르게 답변 주셔서 고맙습니다.

구글 링크를 보내 드립니다.

https://drive.google.com/file/d/1osnXrvBR66iXkdFrryLZJUdNpaNLL8Zi/view?usp=drive_link

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

구글 링크를 "전체공개"로 변경해주실 수 있으실까요?

 

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

액세스 권한 필요

액세스를 요청하거나 액세스 권한이 있는 계정으로 전환하세요.

현재는 접근 권한이 없다고 나옵니다!

0

안녕하세요, 인프런 AI 인턴입니다. Sam님, 질문 주셔서 감사합니다.

강의를 수강하시면서 XML 레이아웃에서 “프롤로그에서 콘텐츠가 허용되지 않습니다.“라는 오류를 만난 것을 말씀해 주셨습니다. 이 오류는 일반적으로 XML 파일에서 잘못된 형식이나 구성 요소가 올바르지 않게 중첩되어있는 경우 발생할 수 있습니다.

우선, 아래 몇 가지 주요 원인을 점검해 보시기 바랍니다:

  1. LinearLayout 내부 요소: LinearLayout에 자식 요소를 배치할 때, 자식 요소의 layout_width 또는 layout_height를 “match_parent”로 설정하지 말고 “wrap_content”로 설정하거나 배치 크기를 조정할 필요가 있을 수 있습니다. “match_parent”가 내부 뷰에 사용되면 뷰가 LinearLayout의 크기 전부를 차지하려 할 수 있어 이상 작동할 수 있습니다.

  2. Constraint Layout: ConstraintLayout을 사용할 때는 각 뷰의 제약 조건을 명확히 정의해야 합니다. 특히 LinearLayout처럼 배치할 경우, 상하좌우 제약 조건이 정확히 설정되었는지 확인하세요.

  3. 앱 컴파일러 업데이트: Otter나 최신 안드로이드 버전 일부에서는 레이아웃의 불일치를 엄격하게 확인하기 때문에 문제를 일으킬 수 있습니다. 이 경우, Android Studio에서 제공하는 “Invalidate Caches / Restart” 기능을 사용해 보고, 앱 SDK와 빌드 툴을 최신 버전으로 업데이트해 보는 것도 좋은 방법입니다.

관련된 질문과 유사한 문제를 해결한 게시물을 이곳에서 찾아보실 수 있습니다. 게시물에서는 SDK 버전 업데이트 문제에 관한 대화와 해결 방법이 언급된 바 있으니 참고하시기 바랍니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

Keys님의 프로필 이미지
Keys
질문자

AI 답변 방식으로도 잘 해결되지 않습니다.

Keys님의 프로필 이미지
Keys

작성한 질문수

질문하기