Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 943
user2071938 Avatar asked Nov 11 '13 11:11

user2071938


2 Answers

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">
like image 92
Lucas Arrefelt Avatar answered Sep 19 '22 03:09

Lucas Arrefelt


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.

like image 45
AjOnFire Avatar answered Sep 21 '22 03:09

AjOnFire