Eamorr Eamorr - 23 days ago 16
Android Question

Nudge a button to the left

I'm very new to Android and I have the following 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>


This produces the following layout:

alt text

How can I nudge the rightmost button to the left?

Answer

Instead of a TableLayout, try using a RelativeLayout:

<?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>
Comments