Ich las dies: How to align linearlayout to vertical center? Aber es hat mir nichtAndroid lineares Layout Zentrierung
hilft Grundsätzlich versuche ich, in der Mitte meines Bildschirms zum Zentrum 2 ImageButtons
. Die beiden Tasten sind in einer linearLayout
horizontal ausgerichtet.
Ich versuchte, eine relativeLayout
mit vertikaler Ausrichtung zu verwenden, um die zwei imagebuttons
in der Mitte in der vertikalen Richtung zu zentrieren, aber das scheint die Arbeit nicht zu tun.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/white"
tools:context="com.example.max.testcase.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:padding="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="@color/white"
android:textSize="16sp"
android:background="@color/blue"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<ImageButton
android:id="@+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:adjustViewBounds="true"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="@color/white"
android:src="@drawable/icon1" />
<ImageButton
android:id="@+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="@color/white"
android:src="@drawable/icon2"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Die beiden Tasten auf der oberen Menüleiste, halten kleben
Was ist, wenn ich eine Fußzeile hinzufügen möchte? Jetzt, da es match_parent ist, kann ich nichts darunter hinzufügen. Ich habe versucht, es zu wrap_content zu ändern und dann eine Fußzeile mit relativer_Layout hinzuzufügen, aber das führt wieder zu den Knöpfen – Jbv2
@ Jbv2 Fügen Sie in diesem Fall nur diese Fußzeile in RelativeLayout hinzu (eine mit der Höhe match_parent), und richten Sie sie an unten als - 'android: alignParentBottom =" true "' – All