2013-12-14 10 views
6

Ich habe lineare vertikale Anordnung in Eltern. Dann wird ein horizontales lineares Layout in dem Boden darunter 3 TastenWie 3 Tasten in einer Linie ausrichten, Android?

ich auf der linken Seite der Aktivität 1.e Taste will in der unteren 2. Taste in der Mitte und 3. Taste in der rechten Seite

Hier ist die XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/viewImageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:contentDescription="@null" 
    android:src="@drawable/ic_launcher" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:layout_gravity="fill_vertical" 
     android:text="Button" /> 
</LinearLayout> 

Antwort

11

Für jene Art der Ausrichtung (eine Taste in extremen Linken Anwendung des Elternteils, ein anderes in der Mitte und ein mehr im äußersten Recht des Elternplanes) RelativeLayout wird m sein Erz praktisch als die LinearLayout .Because, wenn Sie RelativeLayout als Eltern-Layout für Ihre Tasten verwenden Sie die Verwendung von android:layout_alignParentLeft="true" für eine button machen können Sie in ausrichten möchten extreme links, android:layout_centerInParent="true" in Zentrum ausrichten und android:layout_alignParentRight="true" auf ein ausrichten Knopf in rechts Seitenecke.

die Sie interessieren ..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/viewImageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:contentDescription="@null" 
    android:src="@drawable/ic_launcher" /> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:text="Button" /> 
</RelativeLayout> 

</LinearLayout> 
+0

Dank es funktioniert für mich – WISHY

+0

@Wishy Wenn meine Antwort Sie geholfen hatte, es pls akzeptieren. Und gehen Sie durch meine Bearbeitung für weitere Erklärungen. – Hariharan

4

die Ausrichtung gesetzt hat horizontale

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

    <Button 
     android:id="@+id/button1" 
     android:layout_weight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_weight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_weight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:layout_gravity="fill_vertical" 
     android:text="Button" /> 
</LinearLayout> 

und Verwendung Gewichte für Tasten

Schnapp

enter image description here

1

ja können Sie tun, indem layout_weight=1

  <?xml version="1.0" encoding="utf-8"?> 
      <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
android:layout_alignParentBottom="true"> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="left " /> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Center" /> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Right" /> 

     </LinearLayout> 
    </RelativeLayout> 
Verwandte Themen