Chcę utworzyć wymienia dwie kolumny formularza wejściowego takiego:Jak utworzyć zgrabny formularz wprowadzania dwóch kolumn w systemie Android?
Moje xml kodu układ do tej pory:
<?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>
Widać, że użyłem LinearLayout wykorzystując layout_weight & layout_width = "0dp", aby podział dwóch kolumn wyglądał zadowalająco. W kodzie HTML możemy użyć% szerokości. Ale w układzie androida xml nie ma% -wartości dla layout_width. Chcę uniknąć zakodowanych wartości dp dla szerokości kolumny. Czy to możliwe w Androidzie?
Jak na razie to najlepsze, co mogę zrobić. Teraz chcę zmienić rozmiar pola tekstowego ISBN, aby stał się mniejszy (50% mniej od bieżącego rozmiaru). Ale nie mogę zmienić rozmiaru szerokości pola tekstowego, ponieważ layout_width musi mieć wartość "0dp", aby układ_waga działała. Ja też chcę zrobić to samo z przyciskiem Zatwierdź i Anuluj.
Zastanawiam się, czy korzystanie z LinearLayout jest poprawnym sposobem tworzenia formularzy wejściowych w systemie Android. Czy TableLayout może być lepszy? Słyszałem, że nie można zmienić wielkości layout_width widoku podrzędnego w TableLayout.
Jest kilka osób, które polecają mi używanie RelativeLayout, próbowałem go, ale nie obsługuje on layout_weight.
Z powodu tego powodu używa względna Układ zapewnia maksymalną elastyczność i można zmienić pojedynczy widok w zależności od potrzeb .... –
Proponuję użyć względna Układ, ponieważ zapewnia większą elastyczność. –
@both of you above: staraj się dać przykład? – null