/ / Gleiche Tastenbreiten in einer Ansicht - Android, relative Layout

Gleiche Tastenbreiten in einer Ansicht - Android, relative Layout

Ich würde gerne wissen, ob Sie mit RelativeLayoutkann zwei oder drei Knöpfe nebeneinander positionieren und ihre Breite ist gleichmäßig über die Ansicht eingestellt. z.B. Wenn der Bildschirm 300 Pixel groß ist, nehmen die Schaltflächen automatisch jeweils 100 Pixel Breite an (ohne Padding usw.).

Ich kann Code nicht wirklich bereitstellen ... Weil ich nicht weiß wie es geht = 0)

Antworten:

4 für die Antwort № 1

Ich würde ein lineares Layout in Ihr relatives Layout einfügen (vorausgesetzt, Sie benötigen das relative Layout für etwas anderes) mit horizontaler Ausrichtung und geben Sie jedem Button das gleiche Gewicht.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right|center_vertical">

<!--  Some stuff above -->
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_alignParentLeft="true">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="left" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:layout_weight="1"
android:text="center"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btn2"
android:layout_weight="1"
android:text="right"/>

</LinearLayout>
<!--  Or below -->
</RelativeLayout>