user2071938
user2071938

Reputation: 2255

Android RelativeLayout margin

I have following XML layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@layout/light_list_item_border"
android:orientation="vertical" >

<Button
   android:id="@+id/light_list_item_lightdim_button"
   android:layout_width="75dp"
   android:layout_height="40dp"
   android:layout_alignParentRight="true"
   android:layout_alignParentTop="true"
   android:background="@drawable/button_on"
   android:text="@string/button_on"
   android:textColor="@color/white" 
   android:layout_margin="5dp"
   />

<TextView
   android:id="@+id/light_list_item_lightrgb_label"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignBaseline="@+id/light_list_item_lightdim_button"
   android:layout_alignBottom="@+id/light_list_item_lightdim_button"
   android:layout_alignParentLeft="true"
   android:text="@+id/label"
   android:layout_marginLeft="5dp"
   android:textColor="@color/white"
   android:textSize="15sp" />

<TextView
   android:id="@+id/light_list_item_lightrgb_labelSzene"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_below="@+id/light_list_item_lightdim_button"
   android:layout_marginLeft="5dp"
   android:text="@+id/label"
   android:textColor="@color/white"
   android:textSize="15sp" />

<Button
   android:id="@+id/Button01"
   android:layout_width="75dp"
   android:layout_height="40dp"
   android:layout_alignParentRight="true"
   android:layout_alignParentBottom="true"
   android:layout_below="@+id/light_list_item_lightdim_button"
   android:layout_marginBottom="5dp"
   android:layout_marginRight="5dp"
   android:background="@drawable/button_on"
   android:text="@string/button_add"
   android:textColor="@color/white" />
 </RelativeLayout>

but for any case:

android:layout_marginBottom="5dp"

of the 2nd button is 'ignored'?

Here you can see my Problem: the buttons labeled with a "+" should have a margin of 5 to the bottom border.

I have tried android:paddingBottom as well, but doesn't succeeded Screenshoot

Thanks

Upvotes: 6

Views: 33306

Answers (6)

Lucas Arrefelt
Lucas Arrefelt

Reputation: 3929

I think we need to see your "@layout/light_list_item_border" to be able to solve this. But for this problem, wouldnt it be easier to put padding on the relative layout itself, and skip all the margins?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@layout/light_list_item_border"
android:padding="5dp">

Upvotes: 12

Mohit Verma
Mohit Verma

Reputation: 1660

In values/dimens.xml file you can set margins.

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

Upvotes: 0

Try this one:

Remove the property: android:layout_alignParentRight="true"

And your new code for 2nd button looks like:

 <Button 
 android:id="@+id/Button01"  
 android:layout_width="75dp"  
 android:layout_height="40dp"   
 android:layout_below="@+id/light_list_item_lightdim_button"   
 android:layout_marginBottom="5dp"   
 android:layout_marginRight="5dp" 
 android:background="@drawable/button_on"   
 android:text="@string/button_add"    android:textColor="@color/white"
 />

Upvotes: 0

Subramanian Ramsundaram
Subramanian Ramsundaram

Reputation: 1347

Remove these two lines:

android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"

Add

android:layout_margin="5dp"

Upvotes: 2

krishna
krishna

Reputation: 4099

just add this after button in xml

<View
       android:layout_width="75dp"
       android:layout_height="5dp"
       android:layout_below="@+id/plusbuttonid" />

Upvotes: 3

AjOnFire
AjOnFire

Reputation: 2878

If you want some space between layout and its content try providing a padding property to the relative layout itself say 5dp and remove unnecessary margin properties.

Upvotes: 4

Related Questions