Ich habe zwei lineare Layouts ineinander. In der zweiten habe ich eine Switch
Taste, eine TextView
und eine FloatingActionButton
. Ich möchte diese 3 in die gleiche Zeile setzen und ich möchte den Switch und die TextView
zentralisieren und ich möchte die FloatingActionButton
auf der rechten Seite des Bildschirms ausrichten. Ich habe versucht, marginLeft
zu verwenden, um sie zu zwingen, zu der Position zu gehen, die ich will, aber ich glaube, dass das nicht der richtige Weg ist.Android: Zentrum und rechts Ausrichtung innerhalb LinearLayout
mein Code hier (jetzt die 3-Komponenten sind bereits in der gleichen Zeile):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:weightSum="1" >
<Switch
android:id="@+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="140dp"
android:layout_marginTop="20dp"
android:theme="@style/SCBSwitch"
/>
<TextView
android:id="@+id/OpenClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:text="Open"
android:textSize="20dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/action_find_location"
android:layout_width="277dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="75dp"
android:layout_marginRight="10dp"
android:src="@drawable/calendar_today"
fab:backgroundTint="@color/theme_color"
fab:borderWidth="0dp"
fab:elevation="9dp"
fab:rippleColor="@color/toolbar_title_color"
fab:fabSize="mini"/>
</LinearLayout>
</LinearLayout>
haben Sie versuch android: layout_gravity = "left"; android: layout_gravity = "zentrum"; android: layout_gravity = "right" für jede Steuerung bzw. – user3501749
Danke für die Antwort! Ja, ich habe es versucht, aber es hat nicht funktioniert. Ich weiß nicht, ob es wegen eines der anderen Attribute nicht funktioniert. –