Android自定义对话框高度

前端之家收集整理的这篇文章主要介绍了Android自定义对话框高度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@我正在学习 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"

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

解决方法

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

添加,the Android SDK表示RelativeLayout的子项不能对Layout具有依赖性,例如align_parent_bottom.我假设fill_parent是一个依赖项,因此打破了布局.

原文链接:https://www.f2er.com/android/309664.html

猜你在找的Android相关文章