Ich mag ein sauberes Zwei Spalten Eingabeformular wie folgt erstellen:Wie erstelle ich ein nettes zweispaltiges Eingabeformular in Android?
CodeMein xml Layout so weit: können
<?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>
Sie sehen, dass ich Linearlayout verwendet verwendet layout_weight & layout_width = "0dp" Trick, um die zwei Spalten Division ordentlich aussehen zu lassen. Im HTML-Code können wir mit% width size verwenden. Aber im android XML-Layout gibt es keinen% -Wert für layout_width. Ich möchte hartcodierte dp-Werte für die Spaltenbreite vermeiden. Ist es bei Android möglich?
Bis jetzt ist das das Beste, was ich tun kann. Jetzt möchte ich die Größe der ISBN-Textbox verkleinern (50% kleiner als die aktuelle Größe). Aber ich kann die Breite des Textfelds nicht ändern, da layout_width "0dp" sein muss, damit layout_weight funktioniert. Ich möchte auch das gleiche mit der Größe der Schaltfläche Submit und Cancel tun.
Ich frage mich, ob die Verwendung von LinearLayout eine korrekte Methode ist, um Eingabeformular ordentlich in Android zu erstellen. Könnte TableLayout dafür besser sein? Ich habe gehört, dass Sie in layout_widget nicht die layout_width der Kindansicht ändern können.
Es gibt einige Leute hier, die mir empfehlen, RelativeLayout zu verwenden, ich habe es versucht, aber es unterstützt nicht layout_weight.
Aus diesem Grunde i Relative Layout verwendet es ein Maximum an Flexibilität bietet und Sie können eine einzelne Ansicht nach Ihrem Bedarf ändern .... –
Ich würde vorschlagen, Relativ zu verwenden Layout, weil es mehr Flexibilität bietet. –
@both von Ihnen oben: geben Sie ein Beispiel? – null