Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is layout_marginBottom ignored when using wrap_content?

I have the following layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#FF0000" >

<RelativeLayout
    android:id="@+id/usericon_img"
    android:layout_width="73.3334dp"
    android:layout_height="70.6667dp"
    android:layout_marginBottom="2.6667dp"
    android:layout_marginLeft="3.3334dp"
    android:layout_marginTop="2.6667dp"
    android:background="#FFFFFF" />
</RelativeLayout>

On the emulator (I've tested it on a real device and it looks the same) the layout looks like this:

My question is: why I don't have a red margin under the white layout? I know that if I change the outer layout to:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="76dp"
android:background="#FF0000" >

I'll get what I want, but why doesn't wrap_content work properly?

like image 328
Toorop Avatar asked Apr 30 '12 15:04

Toorop


People also ask

What is the purpose of Android Layout_width Wrap_content?

wrap_content is used to wrap the view according to its actual size. It can be used with layout_height as well as layout_width. If we set layout_height as wrap_content then the height will be the same as the content size and if we set layout_width as wrap_content then the width will be the same as the content size.

What does Wrap_content mean?

wrap_content — The component just want to display big enough to enclose its content only.


1 Answers

In the documentation:

To measure its dimensions, a view takes into account its padding.

If I am not mistaken it means that margin is not added to the dimension. That means wrap_content works correctly but don't take margin into account.

Just a short question: Why do you use values like 70.6667dp?

like image 141
WarrenFaith Avatar answered Oct 10 '22 20:10

WarrenFaith