Frage

Ich bin sehr neu für Android und ich habe folgendes Layout XML-Code:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:background="#CCC">

    <TableRow
    android:background="#333"
    android:padding="10px">
     <Button 
     android:text="Sign-up"
     android:id="@+id/signUp"
     android:layout_width="wrap_content"
     android:textSize="18px"
     android:layout_height="wrap_content"
     android:layout_gravity="left">
     </Button>

     <Button 
     android:text="About"
     android:id="@+id/about"
     android:layout_width="wrap_content"
     android:textSize="18px"
     android:layout_height="wrap_content"
     android:layout_gravity="right"
     android:gravity="">
     </Button>

    </TableRow>
</TableLayout>

Dies erzeugt das folgende Layout:

alt text

Wie kann ich den Knopf ganz rechts nach links verschieben?

War es hilfreich?

Lösung

Statt eines TableLayout, versuchen, eine RelativeLayout mit:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#CCC">

    <Button 
        android:text="Sign-up"
        android:id="@+id/signUp"
        android:textSize="18px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"/>

    <Button 
        android:text="About"
        android:id="@+id/about"
        android:textSize="18px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"/>

</RelativeLayout>

Andere Tipps

Versuchen Sie padding auf die Schaltfläche Einstellung:

<TableRow
android:background="#333"
android:padding="10px">
 <Button 
 android:text="Sign-up"
 android:id="@+id/signUp"
 android:layout_width="wrap_content"
 android:textSize="18px"
 android:layout_height="wrap_content"
 android:layout_gravity="left">
 </Button>

 <Button 
 android:text="About"
 android:id="@+id/about"
 android:layout_width="wrap_content"
 android:textSize="18px"
 android:layout_height="wrap_content"
 android:layout_gravity="right"
 android:gravity=""
 android:padding="3dip" >
 </Button>

</TableRow>

Hier finden Sie aktuelle dieser Tutorial, es tut etwas sehr ähnlich zu dem, was Sie suchen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top