I have a RecyclerView
, in which the item views are created by inflating a layout within a custom view, with a ConstraintLayout
at its root.
When I set the child view to have width wrap_content
it works fine.
But when I set the second child view to have width 0dp
("match_constraint"), strange things happen.
Here's my item layout:
<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="wrap_content"
>
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TextView"
/>
<TextView
android:id="@+id/myTextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="@color/text_color_dark_primary"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/myTextView"
tools:text="TextView"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
When myTextView2 has width wrap_content
, all is good. But when I make it 0dp
, all hell breaks loose.
The issue only occurs on the second TextView - the first TextView can have width wrap_content
or 0dp
, and both work as expected. But when the second TextView has width 0dp
, different issues arise:
myTextView: wrap_content, myTextView1: wrap_content - no issue
myTextView: 0dp, myTextView1: wrap_content - no issue
myTextView: 0dp, myTextView1: 0dp - no items show, infinite scroll
myTextView: wrap_content, myTextView1: 0dp - myTextView shows as a small column on the left of the screen, the rest of the width is blank
Are there any fixes?