Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add spacing in RelativeLayout

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"/>
like image 355
michael Avatar asked May 06 '10 21:05

michael


People also ask

How do I set center in RelativeLayout?

RelativeLayout attributes You can change layout_align parent like top, left, and right. android:layout_centerHorizontal : This attribute is used to center the element horizontally within its parent container. You can change layout_center like layout_centerVertical or layout_centerInParent .

How views are aligned inside a RelativeLayout?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

Can we use RelativeLayout inside ConstraintLayout?

You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

What is the default placement of objects in a RelativeLayout?

Android RelativeLayout We can also position a view with respect to its parent such as centered horizontally, vertically or both, or aligned with any of the edges of the parent RelativeLayout . If none of these attributes are specified on a child view then the view is by default rendered to the top left position.


1 Answers

Fix ids and try android:layout_marginRight="10dip"

like image 75
Alex Volovoy Avatar answered Sep 24 '22 12:09

Alex Volovoy