Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why marginBottom not working?

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/messageLayout"     android:layout_width="fill_parent"     android:layout_height="wrap_content">      <ImageView         android:id="@+id/messageSender"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginRight="10dp"         android:layout_marginLeft="10dp"         android:layout_marginTop="5dp"         android:layout_marginBottom="5dp"/>      <TextView         android:id="@+id/messageSenderName"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toRightOf="@id/messageSender"         android:ellipsize="end"         android:maxLines="1"         android:singleLine="false"         android:textColor="@color/list_text_color"         android:textSize="16dp"         android:layout_marginTop="5dp" />      <TextView         android:id="@+id/messageContent"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toRightOf="@id/messageSender"         android:layout_below="@id/messageSenderName"         android:ellipsize="end"         android:maxLines="1"         android:singleLine="false"         android:textColor="@color/codeFont"         android:textSize="13dp"/> </RelativeLayout> 

In my layout I have problem. When I set marginTop="5dp" it's fine, but when I use marginBottom nothing happens in my layout. Also when I set padding in RelativeLayout it does not work either. What is the problem here? Could you give me any solution?

like image 425
fish40 Avatar asked Dec 27 '11 07:12

fish40


People also ask

Why is my padding-bottom not working?

you have set a fixed height for #main-content due to which the padding-bottom is not effective. Remove height: 300px; property or just replace 300px with auto. Now, the padding-bottom property should work.

How does margin-bottom work?

The margin-bottom CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

Are the negative values allowed in margin property?

It is possible to give margins a negative value. This allows you to draw the element closer to its top or left neighbour, or draw its right and bottom neighbour closer to it.


2 Answers

marginBottom has no effect if you set android:layout_height="wrap_content" for <RelativeLayout>, instead set it as match_parent and check.

like image 82
Paresh Mayani Avatar answered Oct 08 '22 07:10

Paresh Mayani


It is realy just a bug of the <RelativeLayout>, so you could try to wrap the RelativeLayout inside of a <LinearLayout> and set the margin there.

like image 29
Sebastian Baltes Avatar answered Oct 08 '22 06:10

Sebastian Baltes