Thursday, April 21, 2011

How can I add spacing in RelativeLayout

Hi,

I have a Relative Layout. Which has 2 buttons, side by side and it is right-aligned.

So this is my layout xml file. My question is there are no spacing between the right-most button and the right border of the RelativeLayout and between the 2 buttons. How can I add that? I play with android:paddingRight, but nothing helps.

Thank you.

<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="0dp" android:paddingRight="10dp">

    <Button android:id="@+id/1button" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingLeft="10dp" android:paddingRight="10dp"/>

    <Button android:id="@+id/1button" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/1button"
        android:paddingLeft="10dp" android:paddingRight="10dp"/>
From stackoverflow
  • You have duplicated ids for the buttons, try fixing that and see if it looks ok.

    Otherwise, your layout looks good. However, if you fix the ID problem, there will be 20 dip padding on the right (10 from the layout and 10 from the button).

  • android:layout_margin="10dp"
    

    or

    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    
  • Fix ids and try android:layout_marginRight="10dip"

0 comments:

Post a Comment