9
我有以下佈局文件:爲什麼在使用wrap_content時忽略layout_marginBottom?
<?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正常工作?
我已經使用了70.6667,因爲我想在hdpi屏幕上顯示106像素的尺寸。 – Toorop
如果邊距被忽略,爲什麼我有左邊距和上邊距? – Toorop
嘗試使用填充代替 – Ahmad