Android:设置对话框的尺寸( "fill_parent"是什么意思?)

标签 android layout dialog

Android 开发者指南 Creating a Custom Dialog指定开始的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/layout_root"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="10dp"
          >

如果我使用这段代码,我会得到一个位于屏幕中央的对话框,每侧都有大约 40 像素的底层 View 可见。

“fill_parent”到底是什么意思(宽度和高度)?

最佳答案

为了回答 Octavian Damiean,我按照 Creating A Custom Dialog 中列出的代码编写了一个应用程序.我已将指定的 Java 代码放入空白应用程序的 onCreate 方法中(在 super.onCreate(...) 和 setContentView(...) 之后。为了使其运行,我更改了 Java 代码,其中显示“Context mContext = getApplicationContext();”到“Context mContext = this;”,最后我添加了一行“dialog.show();”来显示对话框。

生成的屏幕如下所示:

this

虽然高度和宽度都设置为 fill_parent,但宽度比屏幕宽度小一点,高度比屏幕高度小很多。

我不认为填充按照您建议的方式工作。将它从 10dip 更改为 0dip 没有明显的区别(屏幕边缘和对话框边缘之间仍然存在间隙。)将其更改为 100 dip 结果如下:

alt text

我认为填充会影响 View 中对象的间距,而不是 View 在其父 View 中的间距。

关于Android:设置对话框的尺寸( "fill_parent"是什么意思?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4119755/

相关文章:

c++ - 如何在 Windows 中更改 OPENFILENAME 对话框的位置?

delphi - 如何在Delphi中集中Windows异常对话框?

android - 使用智能位置库的问题

android - 无法通过低功耗蓝牙发现服务和特征 - BLE

css - 侧边栏 div 未填充父级的 100%

html - 具有可变间距的基于 UL 的液体水平菜单

android - 对于 seg faults 的原生 android 应用程序,为什么 logcat 中没有堆栈跟踪?

android - Logcat Message中的pid, uid, gids是什么意思?

html - 响应式两列页脚

android - 无法添加窗口错误