<?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?
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.
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.
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.
marginBottom
has no effect if you set android:layout_height="wrap_content"
for <RelativeLayout>
, instead set it as match_parent and check.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With