Android: setting the dimensions of a Dialog (what does “fill_parent” mean?)
关于创建自定义对话框的Android开发人员指南指定了以以下内容开头的布局:
1 2 3 4 5 6 7 | <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个像素的基础视图。
" fill_parent"到底是什么意思(对于宽度和高度)?
为响应Octavian Damiean,我按照创建自定义对话框中列出的代码编写了一个应用程序。我已经将指定的Java代码放入空白应用程序的onCreate方法中(在super.onCreate(...)和setContentView(...之后)。为了使其运行,我更改了Java代码,其中显示" Context mContext =将" getApplicationContext();"添加到" Context mContext = this;",最后我添加了" dialog.show();"行以显示对话框。
结果屏幕如下所示:
尽管将height和width都设置为fill_parent,但宽度比屏幕宽度小一点,并且高度比屏幕高度小得多。
我认为填充不像您建议的那样起作用。将其从10dip更改为0dip并没有明显的区别(屏幕边缘和对话框边缘之间仍然存在间隙。)将其更改为100 dip将导致:
我认为填充会影响View中对象的间距,而不是View父对象中View的间距。
这实际上意味着它的意思。它填充了其父容器的整个空间。在这种情况下,由于padding属性的缘故,每侧(即左,上,右,下)均为负
这是有关fill_parent的更多信息,这里是有关ViewGroup.LayoutParams的更多信息。