Ich habe drei Tasten müssen in einer Zeile am unteren Rand des Bildschirms befinden. Unten ist der Code in Aktivität xml. Um die drei Schaltflächen platzsparend zu machen, wickle ich sie jeweils in ein LinearLayout und setze das Layout android:layout_weight
auf 1 und android:layout_gravity
in die Mitte.Wie werden drei gleichmäßig unter LinearLayout angeordnete Schaltflächen angeordnet?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90px"
android:background="#88104502"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/goBack"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/back"
android:onClick="toHomePage" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/findPlant"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/flowr"
android:onClick="toImagePage" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_weight="1">
<Button
android:id="@+id/plantList"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/list" />
</LinearLayout>
</LinearLayout>
Aber es wird der Knopf nicht in der Mitte des Linearlayout entfernt. Unten ist der Screenshot:
Sie, dass jede Taste auf der linken Seite des Linearlayout befindet sich sehen können. Wie man sie zentriert macht?
Warum verwenden Sie drei verschiedene lineare Layouts? Es wird auch mit einem HauptlinearLayout gemacht und gibt 3 Tasten gleiches Gewicht. –