Search code examples
javaandroidandroid-buttonandroid-relativelayout

How to position a button exactly how I want it?


I'm using RelativeLayout. I understand using Graphical Layout you can't position a button too well. How can I do it in XML? I've tried changing the marginLeft, but nothing moves.

All I want to do is position my buttons!

<Button
    android:id="@+id/ListsButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/EditButton"
    android:layout_alignBottom="@+id/EditButton"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="18dp"
    android:text="Li" />

Solution

  • You can use marginLeft, marginRight, marginTop, and marginBottom for small adjustments. If you want to do larger adjustments you can use blank elements in combination with weights, or use a RelativeLayout in combination with alignParentBottom, alignParentTop, alignParentRight, and/or alignParentLeft