Как создать аккуратную форму ввода с двумя столбцами в Android?

Я хочу создать аккуратную форму ввода с двумя столбцами, подобную этой:

http://img31.imageshack.us/img31/115/addnew2.png

Пока мой код макета xml :

<?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="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="@string/lblTitle" />

        <EditText
            android:id="@+id/txtTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="@string/lblAuthor" />

        <EditText
            android:id="@+id/txtAuthor"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="@string/lblPublisher" />

        <EditText
            android:id="@+id/txtPublisher"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="@string/lblIsbn" />

        <EditText
            android:id="@+id/txtIsbn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.75"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <View
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25" />

        <Button
            android:id="@+id/btnSubmit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.375"
            android:text="@string/submit" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.375"
            android:text="@string/cancel" />
    </LinearLayout>

</LinearLayout>

Вы можете видеть, что я использовал LinearLayout, используя трюк layout_weight & layout_width="0dp", чтобы разделение на два столбца выглядело аккуратно. В HTML-коде мы можем использовать с размером % ширины. %-значение для layout_width. Я хочу избежать жестко заданных значений dp для ширины столбца. Возможно ли это в Android?

Пока это лучшее, что я могу сделать. Теперь я хочу изменить размер текстового поля ISBN, чтобы оно стало меньше (50% размер меньше текущего размера). Но я не могу изменить ширину текстового поля, так как layout_width должен быть "0dp" для работы layout_weight. Я также хочу сделать то же самое с размером кнопки «Отправить» и «Отменить».

Интересно, если использовать LinearLayout это правильный способ аккуратного создания формы ввода в Android. Может ли TableLayout лучше для этого? Я слышал, что вы не можете изменить layout_width дочернего представления в TableLayout.

Здесь есть люди, которые рекомендуют мне использовать RelativeLayout, я пробовал, но он не поддерживает layout_weight.

16
задан null 25 May 2012 в 09:31
поделиться