使用wrap_content时为什么忽略layout_marginBottom?

问题描述 投票:9回答:1

我有以下布局文件:

<?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>

在模拟器上(我在真实设备上测试它看起来一样),布局如下所示:

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

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

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

android margin relativelayout
1个回答
6
投票

documentation

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.