Android自定义对话框高度

Pet*_*son 6 android dialog

我正在学习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>      
  />
Run Code Online (Sandbox Code Playgroud)

我得到了这个对话框...

替代文字

但是Developer.Android.com说......

" WRAP_CONTENT,这意味着视图要大到足以包含其内容(加上填充) "

...那么为什么对话框要比它需要的高得多呢?

如果我用.替换布局高度

  android:layout_height="200px"
Run Code Online (Sandbox Code Playgroud)

它做了一个适当的简短对话,但我不想使用明确的像素高度(这不是好习惯).如何使对话框的内容足够大?

And*_*wKS 7

您将TextView的高度设置为fill_parent.是否有可能将此相对于RelativeLayout的高度与wrap_content一起将其高度推到最大尺寸?如果将TextView高度更改为wrap_content会发生什么?

要添加,Android SDK会说RelativeLayout的子项不能依赖于Layout,例如align_parent_bottom.我假设fill_parent是一个依赖项,因此打破了布局.