Mon problème est très similaire à this question, mais contrairement à son OP je passe le parent
au LayoutInflater
. J'utilise la bibliothèque de support 25.3.1. Voici la mise en page que je gonfler (Changer le ConstarintLayout
à LinearLayout
ne contribue pas):enfants RecyclerView match_parent
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="72dp"
android:background="?android:selectableItemBackground"
android:clickable="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/list_text_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.ListPrimary"
app:layout_constraintBottom_toTopOf="@+id/list_text_secondary"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:ignore="Deprecated"
tools:text="list_text_primary"/>
<TextView
android:id="@+id/list_text_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:gravity="center_vertical"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.ListSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/list_text_primary"
tools:ignore="Deprecated"
tools:text="list_text_secondary"/>
</android.support.constraint.ConstraintLayout>
J'ai aussi essayé de régler le LayoutParams
manuellement dans onCreateViewHolder
comme décrit here. Je pensais que cela fonctionnait, mais de temps en temps, le parent
aura une largeur et une hauteur de 0 (je suis incapable d'identifier la raison) qui rend l'enfant invisible. Selon this answer le RecyclerView
devrait déjà me mesurer par le temps onCreateViewHolder
est appelé.