android:layout_gravity ne fonctionne pas comme prévu

J'ai un simple LinearLayout avec un TextView et une ImageView. Je veux que le texte dans le TextView pour être aligné à droite, mais le résultat montrer que le Texte est aligné à gauche. Il n'y a rien de mal avec ma mise en page xml? Merci.

<?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 que vous avez mentionné ne fonctionne pas non plus.

J'ai essayé d'utiliser RelativeLayout, mais encore, elle m'a donné comme résultat:
Plus De Commentaires (Icône)

Ce que j'ai prévu est
Plus De Commentaires (Icône)

Le RelativeLayout xml est ci-dessous. Il n'y a rien de mal à cela?

<?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>

À la suite de la solution de contournement de Michael commentaire, j'ai le code XML ci-dessous. J'ai attendu la sortie:

     RightLeft

mais la production réelle est:

Right             Left

Donc la solution de contournement ne fonctionne pas pour moi. Toutes les 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 fichier xml?
Il l'a fait, il n'avait tout simplement pas le formater.
(aussi: modifié de sorte qu'il est visible, et visible code ...)
BTW, Quelle est la façon correcte de format de code pour poster du code xml ou ici?
pour les blocs de code, il est plus facile pour entourer le code (exemple<imageView>) avec un arrière-tique de chaque côté. Pour les blocs de code, vous pouvez soit sélectionner le bloc de code et cliquez sur "1010" bouton comme vous écrivez votre réponse/question, ou tiret chaque ligne de code en quatre espaces.

OriginalL'auteur user256239 | 2010-01-22