Je suis confronté à ce problème pour la première fois, mon texte chevauche le bouton, j'ai essayé d'utiliser une barrière, des lignes directrices mais obtenir le texte au centre du bouton et démarrer le parent. J'obtiens que le texte textViews commence sur le parent et se termine le bouton avant et le bouton reste toujours à la fin du parent comme sur l'image ci-dessous.
Ma mise en page.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/titleTextView"
android:text="title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleTextView"
android:id="@+id/descriptionTextView"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/copyImageView"
android:tint="?android:textColorSecondary"
android:src="@drawable/ic_content_copy_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
3 Réponses :
android:layout_marginEnd="8dp"
maintenant vous devez définir la contrainte avec ImageView code > comme ceci
app: layout_constraintEnd_toStartOf = "@ + id / copyImageView"
maintenant au-dessus de la ligne empêchera toujours votre vue de texte de se chevaucher
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Lorem ipsum dolor sit amet, consectetur erererereradipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="@+id/copyImageView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleTextView" />
<ImageView
android:id="@+id/copyImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_content_copy_black_24dp"
android:tint="?android:textColorSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.050000012" />
</androidx.constraintlayout.widget.ConstraintLayout>
C'est aussi une bonne solution mais mr. La solution svkaka est simple. Merci pour votre réponse.
Vous pouvez ajouter une icône à la fin de TextView en ajoutant un dessin à droite / à l'extrémité. Utilisez le code ci-dessous pour ajouter un dessinable à TextView. Vous pouvez également définir un remplissage de dessin pour faire de l'espace entre le dessin et le texte.
android:drawableRight="@drawable/search_icon"
Cela semble une bonne solution mais je m'en tiendrai aux contraintes.
Vous devez définir la largeur sur 0dp, ce qui signifie match_constraint et contraint également sa fin au début de ImageView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/titleTextView"
android:text="title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleTextView"
android:id="@+id/descriptionTextView"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
app:layout_constraintEnd_toStartOf="@id/copyImageView"
android:layout_width="0dp"
android:layout_height="0dp"/>
<ImageView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/copyImageView"
android:tint="?android:textColorSecondary"
android:src="@drawable/ic_content_copy_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
réponse parfaite.