J'ai un LinearLayout simple avec un TextView et un ImageView. Je veux que le texte dans le TextView soit aligné à droite, mais le résultat montre que le texte a été aligné à gauche. Y a-t-il quelque chose qui ne va pas avec ma mise en page xml? Merci.android: layout_gravity ne fonctionne pas comme prévu
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#E8E3E4">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<TextView android:layout_width="260dp" android:layout_height="wrap_content"
android:text="More Comments" android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content" android:src="@drawable/arrow_right"
android:layout_gravity="center" android:scaleType="centerInside" />
</LinearLayout>
</LinearLayout>
Merci, Michael. Mais la solution de contournement que vous avez mentionnée ne fonctionne pas non plus.
J'ai essayé d'utiliser RelativeLayout, mais il m'a donné encore comme résultat: Plus Commentaires (Icône)
Ce que j'attendu est Plus Commentaires (Icône)
Le xml RelativeLayout est au-dessous. Y a-t-il quelque chose qui ne va pas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="@drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="@id/label" />
</RelativeLayout>
Après la solution de contournement dans le commentaire de Michael, j'ai le code XML ci-dessous. Je pensais que la sortie soit:
RightLeft
mais la sortie réelle est:
Right Left
Donc, la solution de contournement ne fonctionne pas pour moi. Des pensées?
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1.0"
android:text="RIGHT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="LEFT"/>
</LinearLayout>
Pouvez-vous inclure votre xml? – jball
Il l'a fait, il ne l'a pas formaté. –
(aussi: édité pour qu'il soit visible, et visible * comme code * ...) –