Ich bin neu in der Android-Entwicklung und habe eine Frage zum Festlegen des Gewichts in einem linearen Layout.
Ich versuche, eine Zeile mit zwei benutzerdefinierten Schaltflächen und einem benutzerdefinierten Bearbeitungstext zu erstellen. Der Bearbeitungstext sollte nur so viel Platz einnehmen wie sein Inhalt, und die beiden Schaltflächen sollten horizontal erweitert werden, um den Rest des verfügbaren Platzes in der Zeile auszufüllen. So was...
| [#Button++#] [#Button--#] [et] |
Nach mehreren Versuchen ist dies das Beste, was ich erreichen kann, obwohl es zu kompliziert erscheint.
| [Button] [Button] [###ET###] |
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_plus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_plus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/tv_dice_plus"
android:text="@string/tv_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_minus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_minus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/btn_minus"
android:text="@string/tv_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<EditText
android:textColor="#FAFAF4"
android:text="@string/et_output"
android:id="@+id/et_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:selectAllOnFocus="true"
android:minWidth="50sp"
android:maxWidth="50sp"
android:background="@drawable/tv_black_background3"
android:textColorHighlight="#c30505"
></EditText>
</LinearLayout>
</LinearLayout>
Soweit ich weiß, sollte die Einstellung [android: layout_weight = "2"] für die linearen Layouts, in denen sich die Schaltflächen befinden, mehr Platz beanspruchen als der Bearbeitungstext, aber für mich ist das Gegenteil der Fall, da beide die halbe Größe haben.
| [Btn] [Btn] [#####et#####] |
Ich habe so viele verschiedene Kombinationen ausprobiert, dass ich mich nicht einmal an sie erinnern kann, und keine hat funktioniert.