안드로이드(Android)

RecyclerView의 내용이 잘려서 안보이는 경우

이망국 2023. 8. 26. 13:32
728x90
반응형

RecyclerView를 지정하여 item으로 내용을 보여주다 보면 내용이 잘려서 안보이는 경우가 있다.

원래 보여야하는 내용


잘려서 내용이 안보이는 경우

첫번째 사진처럼 마지막의 내용이 링크로 끝나야하는데 두번째 사진처럼 내용이 안보이는 경우가 있다.

이러한 증상이 발생하는 이유는 상위의 레이아웃이 ConstraintLayout이면서 RecyclerView height "wrap_content"로 지정하는 경우에 발생한다.

 

height의 특정 값을 부여해주면 되지만 item 내용에 따라 height을 조절하고 싶기 때문에 다른 방법을 사용해야한다.

 

해결하는 방법은 다음과 같다.

 

item을 보여줄 RecyclerView에

app:layout_constrainedHeight="true"

app:layout_constrainedHeight="true" 를 추가하면 된다.

 

나의 경우 RecyclerView를 감싸고 있는 ScrollView가 있어 ScrollView와 RecyclerView에 둘다 넣어줬다. 아래처럼 말이다.

   <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="30dp"
        android:layout_marginTop="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.03"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/line"
        app:layout_constraintVertical_bias="0.0"
        app:layout_constrainedHeight="true"
        android:scrollbars="none">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rankDetailRecyclerView"
        android:layout_width="330dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.03"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/line"
        app:layout_constraintVertical_bias="0.0"
        app:layout_constrainedHeight="true" />

    </ScrollView>

 

그러면

보여주고 싶은 모든 내용이 잘 보여지는걸 확인할 수 있다.

728x90
반응형