0

J'ai besoin mise en page qui montre:mise en page Android: TextView sur le côté droit de la TextView

  1. Si cl__tv_team_name a court texte, il montre (Q) signe à côté de cl__tv_team_name (cl__tv_team_name et (Q) signe sont à côté de l'autre)
  2. Si cl__tv_team_name a long texte, textview il montre avec deux lignes ou plus, mais (Q) signe est encore visible sur le côté droit

Simple LinearLayout ne fonctionne pas. TextView cl__tv_team_name prend toute la largeur.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 


    <TextView 
     android:id="@+id/cl__tv_team_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" /> 

    <TextView 
    android:id="@+id/cl__tv_q_sign" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="(Q)" /> 

</LinearLayout> 

J'ai aussi essayé RelativeLayout sans effet approprié:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical"> 

    <TextView 
     android:id="@+id/cl__tv_team_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_centerVertical="true" 
     android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_toEndOf="@+id/cl__tv_team_name" 
     android:layout_toRightOf="@+id/cl__tv_team_name" 
     android:text="(Q)" 
     android:textSize="13sp" /> 
</RelativeLayout> 

Répondre

3

J'utiliser ConstraintLayout pour y parvenir:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="short text" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/q" 
     app:layout_constraintWidth_default="wrap" 
     app:layout_constraintHorizontal_chainStyle="packed" 
     app:layout_constraintHorizontal_bias="0"/> 

    <TextView 
     android:id="@+id/q" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="(Q)" 
     app:layout_constraintLeft_toRightOf="@+id/text" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBaseline_toBaselineOf="@+id/text"/> 

</android.support.constraint.ConstraintLayout> 

enter image description here

Ou rendre le texte dans la première vue très long:

enter image description here

+0

C'est ce que je voulais réaliser. Je n'ai pas eu le temps d'apprendre la mise en page des contraintes, merci pour votre code. – AppiDevo

+0

Encore une question, Est-il possible de centrer (Q) verticalement? Donc, il sera placé entre la première et la deuxième ligne de la première vue. – AppiDevo

+1

Oui. Pour ce faire, en imposant le haut de 'q' au haut de' text', et le bas au 'text's du bas. Supprime la contrainte de base. –

0

Essayez un mélange des deux Présentation verticale linéaire et horizontale Disposition linéaire à l'intérieur de la disposition relative. Cela semble confus, mais cela fonctionne généralement.

+0

S'il vous plaît placer le travail code. – AppiDevo

0

Cela devrait fonctionner

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical"> 

     <TextView 
      android:id="@+id/q_sign" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:text="(Q)" 
      android:textSize="13sp" /> 

     <TextView 
      android:id="@+id/cl__tv_team_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_centerVertical="true" 
      android:layout_toStartOf="@+id/q_sign" 
      android:layout_toLeftOf="@+id/q_sign" 
      android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" /> 

</RelativeLayout> 
+0

J'ai essayé ceci et lorsque cl__tv_team_name contient du texte court, le signe (Q) est aligné sur le côté droit du conteneur, non sur le nom_team_cl__tv. – AppiDevo

+1

Manqué cette exigence. Avez-vous essayé d'utiliser la disposition des contraintes? –

0

Essayez d'ajouter android: poids = 1 dans votre mise en page LinearLayout fichier xml.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/cl__tv_team_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" /> 

    <TextView 
     android:id="@+id/cl__tv_q_sign" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="(Q)" /> 
</LinearLayout> 
+0

Cela ne fonctionnera pas, vérifiez mes exigences. – AppiDevo

+0

Mon mauvais. J'ai raté l'exigence. Votre exigence semble être un peu difficile. Mais je pense que dans RelativeLayout si vous attribuez maxwidth à cl__tv_team_name textview, cela peut fonctionner. – COD3WORM

+0

Mais je ne sais pas maxwidth de cl__tv_team_name, c'est le problème. Si je le savais, la solution serait très simple;) – AppiDevo