2010-07-25 6 views
4

J'ai un petit problème d'alignement dans LinearLayout. J'essaie d'avoir deux éléments avec l'alignement à gauche et le troisième au centre de l'écran.LinearLayout Center

Voici mon code (nettoyé de id, texte, src):

<?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="fill_parent" 
    android:background="@color/color_background" 
    > 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </ImageView> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal"> 
     </TextView> 
    </LinearLayout> 
</LinearLayout> 

alt text http://img807.imageshack.us/img807/5953/imageg.png

Voici ce que je suis en train de faire, rose et jaune sur la gauche, rouge au centre

pink = imageview 
yellow = 1st texview 
red = 2nd textview 

Une idée?

Répondre

1

Utilisez un RelativeLayout au lieu d'un LinearLayout. Avoir le rose juste être un enfant normal. Avoir jaune utiliser android:layout_toRightOf pour le mettre à la droite du rose. Avoir le rouge android:layout_centerHorizontal="true".

6

Ainsi, le code que vous devez utiliser est la suivante

<?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="wrap_content"> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:id="@+id/image"  
     android:layout_height="wrap_content"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/image"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true"/> 
</RelativeLayout>