Je fais une simple activité de liste avec les composants suivants: un EditText, un RecyclerView, un ProgressBar et un Textview. Tout fonctionne vraiment bien, à l'exception de RecyclerView qui recouvre le texte d'édition et va "au-delà" du bas de l'écran de sorte que le dernier élément soit partiellement découpé (voir les captures d'écran). Qu'est-ce que je fais mal?
Activité principale:
<?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="match_parent"
tools:context="jacopo.com.flickrgallery.GalleryActivity">
<EditText
Android:id="@+id/search_text"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
Android:hint="search by tag..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
Android:id="@+id/gallery_progress"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<Android.support.v7.widget.RecyclerView
Android:id="@+id/gallery_list"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<TextView
Android:id="@+id/gallery_error"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:text="error" />
</Android.support.constraint.ConstraintLayout>
Vous utilisez Android:layout_height="wrap_content"
pour RecyclerView
Mais il semble que vous ayez besoin de limiter la hauteur. Essayez-le avec Android:layout_height="0dp"
. Dans ce cas, il est égal à app:layout_constraintTop_toBottomOf="@+id/search_text"
et app:layout_constraintBottom_toBottomOf="parent"
essayez de suivre, vous devez définir topConstraint
of recyclerview
à edittext
<?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="match_parent" >
<EditText
Android:id="@+id/search_text"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
Android:hint="search by tag..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
Android:id="@+id/gallery_progress"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<Android.support.v7.widget.RecyclerView
Android:id="@+id/gallery_list"
Android:layout_width="0dp"
Android:layout_height="0dp"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<TextView
Android:id="@+id/gallery_error"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:text="error" />
</Android.support.constraint.ConstraintLayout>
Sortie:
Juste utiliser
app:layout_constraintVertical_bias="0.0"
dans la balise recyclerView.
j'espère que cela t'aides.
Dans RecyclerView, ajoutez ceci:
app:layout_constraintStart_toEndOf="@+id/search_text"
Changez votre fichier XML en code ci-dessous.
<?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="match_parent">
<EditText
Android:id="@+id/search_text"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
Android:hint="search by tag..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
Android:id="@+id/gallery_progress"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<Android.support.v7.widget.RecyclerView
Android:id="@+id/gallery_list"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@+id/search_text" />
<TextView
Android:id="@+id/gallery_error"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginEnd="8dp"
Android:layout_marginStart="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:text="error" />
</Android.support.constraint.ConstraintLayout>
Essayez ceci et laissez-moi savoir si cela a fonctionné pour vous.
Vous passez le même identifiant à chaque vue, modifiez votre code avec ceci.
<?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="match_parent">
<EditText
Android:id="@+id/search_text"
Android:layout_width="0dp"
Android:layout_height="wrap_content"
Android:layout_marginTop="8dp"
Android:hint="search by tag..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ProgressBar
Android:id="@+id/gallery_progress"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:layout_editor_absoluteX="376dp" />
<Android.support.v7.widget.RecyclerView
Android:id="@+id/gallery_list"
Android:layout_width="0dp"
Android:layout_height="0dp"
Android:layout_marginBottom="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
Android:id="@+id/gallery_error"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginBottom="8dp"
Android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:text="error"
tools:layout_editor_absoluteX="385dp" />
</Android.support.constraint.ConstraintLayout>
Bonne codage !!