LinearLayout Center - PullRequest
       21

LinearLayout Center

4 голосов
/ 25 июля 2010

У меня небольшая проблема с выравниванием в LinearLayout.

Я пытаюсь получить первый элемент с левым выравниванием, а третий - в центре экрана.

Вот мой код (очищен от id, text, 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>

альтернативный текст http://img807.imageshack.us/img807/5953/imageg.png

Вот что я пытаюсь сделать: розовый и желтый слева, красный в центре

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

Есть идеи?

Ответы [ 2 ]

6 голосов
/ 08 августа 2010

Итак, код, который вам нужно использовать, следующий:

<?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>
1 голос
/ 26 июля 2010

Используйте RelativeLayout вместо LinearLayout.У розового просто будь нормальным ребенком.У желтого используйте android:layout_toRightOf, чтобы поместить его справа от розового.Есть красный использовать android:layout_centerHorizontal="true".

...