我正在學習Android對話框,我對什麼決定了它們的高度感到困惑。如果我將這個XML用於我的對話框佈局。 。 。Android自定義對話框高度
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/AButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10px"
android:text="Click Me to Dismiss"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/AButton"
android:text="Click this button: "
/>
<ImageView
android:id="@+id/an_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="42px"
android:src="@drawable/screw50">
</ImageView>
/>
我得到這個對話框。 。 。
但Developer.Android.com說......
「WRAP_CONTENT,這意味着視圖想要剛好足夠大包圍它的內容(加墊)」
...那麼爲什麼對話遠遠高於它所需要的呢?
如果我更換
android:layout_height="200px"
它使一個正常的短對話,但我不希望使用明確的像素高度(這不是好的做法)的佈局高度。我如何讓對話框的內容足夠大?
是的,我同意LinearLayout沒有這個問題。但是我想使用RelativeLayout,因爲它可以讓我放置。 RelativeLayout有限制嗎? (我應該提到我使用的是Android 2.2,這個問題發生在仿真和實際的手機上。) – 2010-12-01 15:43:00
爲什麼不在LinearLayout中使用RelativeLayout?不,我不知道什麼:( – 2010-12-01 15:43:53
「爲什麼不在LinearLayout中使用RelativeLayout?」我可以嘗試,但它似乎是一個黑客攻擊,沒有進攻。必須有一種方法才能正確工作。 – 2010-12-01 15:45:42