Как я могу заставить свои веса Android LinearLayout работать со значениями 1 и 2? - PullRequest
0 голосов
/ 30 апреля 2011

Я пытаюсь создать LinearLayout, который имеет три строки, каждая из которых имеет одинаковую высоту. Я делаю это, используя 3 LinearLayouts внутри основного, каждый с layout_weight 1. 1. 1001 *

Средняя LinearLayout должна содержать ImageView, TextView, ImageView, с весами 1,2,1. Для этого внутри средней LinearLayout я создал еще 3.

Я хочу, чтобы TextView было в два раза больше каждого ImageView. Если вы видите код ниже, когда layout_weight равен 1 для внутреннего LinearLayouts, у меня нет проблем, эти три появляются одинакового размера. Однако когда я устанавливаю средний (с id = textLayout) на layout_weight=2, он полностью исчезает (как видно в средстве просмотра графического макета Eclipse), и видны только два других.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/fondo"
    android:gravity="center_vertical|center_horizontal">

    <LinearLayout
        android:id="@+id/LayoutTop"
        android:orientation="horizontal"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LayoutMid"
        android:orientation="horizontal"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="1">
            <ImageView
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">
            </ImageView>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/textLayout"
            android:orientation="horizontal"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="2">
            <TextView
                android:text="Status"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            </TextView>
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="1">
            <ImageView
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">
            </ImageView>
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LayoutBottom"
        android:orientation="horizontal"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
    </LinearLayout>

</LinearLayout>

1 Ответ

1 голос
/ 30 апреля 2011

Вам не нужны дополнительные макеты, чтобы правильно расположить средний ряд, а ваши веса задом наперед. Если вы хотите, чтобы текст был в 2 раза больше внешних изображений, вам нужно, чтобы он равнялся 1, а внешние столбцы были равны 1,5

.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout android:id="@+id/LayoutTop"
        android:orientation="horizontal" android:layout_height="0dp"
        android:layout_width="fill_parent" android:layout_weight="1" android:background="#ffff0000"/>


    <LinearLayout android:id="@+id/LayoutMid"
        android:orientation="horizontal" android:layout_height="0dp"
        android:layout_width="fill_parent" android:layout_weight="1">

        <ImageView android:layout_height="fill_parent"
            android:layout_width="fill_parent" android:background="@drawable/icon"
            android:layout_weight="1.5" />
        <TextView android:layout_height="fill_parent" android:id="@+id/TextView01"
            android:layout_weight="1" android:text="Status" android:layout_width="fill_parent" />
        <ImageView android:layout_height="fill_parent"
            android:layout_weight="1.5" android:background="@drawable/icon"
            android:layout_width="fill_parent" />
    </LinearLayout>

    <LinearLayout android:id="@+id/LayoutBottom"
        android:orientation="horizontal" android:layout_height="0dp"
        android:layout_width="fill_parent" android:layout_weight="1" android:background="#ff00ff00"/>


</LinearLayout>

Я использовал значок (если он у вас есть), чтобы поместить картинку в средний ряд, а также несколько цветов в верхней и нижней частях, чтобы более четко показать расстояние.

...