使用wrap_content时为什么忽略layout_marginBottom?

Too*_*rop 9 android margin relativelayout

我有以下布局文件:

<?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>
Run Code Online (Sandbox Code Playgroud)

在模拟器上(我在真实设备上测试它看起来一样)布局看起来像这样:在此输入图像描述

我的问题是:为什么我在白色布局下没有红色边缘?我知道如果我将外部布局更改为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="76dp"
android:background="#FF0000" >
Run Code Online (Sandbox Code Playgroud)

我会得到我想要的,但为什么wrap_content不能正常工作?

War*_*ith 6

文档中:

要测量其尺寸,视图会考虑其填充.

如果我没有弄错,则意味着保证金未添加到维度中.这意味着wrap_content正常工作,但不考虑保证金.

只是一个简短的问题:为什么要使用像这样的值70.6667dp

  • 在测量尺寸时忽略边距但您仍然可以看到它们(至少顶部和左侧是可见的,而底部将位于可见红色区域之外). (2认同)