我正在学习Android对话框,但我不清楚是什么决定了它们的高度。如果我使用以下XML作为我的对话框布局……
<?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"
这个对话框应该是适当短小的,但我不想使用明确的像素高度(这不是一个好习惯)。那么我该如何使对话框的大小刚好能容纳其内容呢?