Aaron
Aaron

Reputation: 4480

Trying to move a button to be on the right side of the screen. My right not the computers right

In the xml I am trying to get the button to be on the right side. Here is my code.

   <TableRow>

    <Button
        android:layout_gravity="right"
        android:gravity="right"
        android:id="@+id/Button01"
        android:text="Sign in" />

   </TableRow>

When I delete the tableRow tags, the button goes the entire width of the screen. I also played around with changing right to left and have still had no luck

Upvotes: 1

Views: 10792

Answers (3)

Jghorton14
Jghorton14

Reputation: 754

This worked for me with in a Frame Layout:

android:layout_gravity="right"

for bottom and right try this:

android:layout_gravity="bottom|right"

Upvotes: 3

Jason Robinson
Jason Robinson

Reputation: 31284

You're missing width and height parameters for your Button. Add these to your button tag:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

Also, layout_gravity will only apply in a LinearLayout or FrameLayout. If you're in a RelativeLayout, use android:layout_alignParentRight="true"

Upvotes: 1

pna
pna

Reputation: 5761

can you change the layout?

Try with:

<TableRow>
 <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
   <Button
    android:layout_alignParentRight="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Button01"
    android:text="Sign in" />
 </RelativeLayout>
</TableRow>

Upvotes: 5

Related Questions