我正在学习关于Android的对话,我感到困惑的是什么决定了他们的高度。如果我用这个XML为我的对话框布局。 。 。
I'm learning about Android dialogs and I'm confused about what determines their height. If I use this XML for my dialog layout . . .
<?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>
/>
我得到这个对话框。 。 。
I get this dialog . . .
但Developer.Android.com说...
But Developer.Android.com says that...
* WRAP_CONTENT,这意味着该视图希望成为刚好足够大以封闭其内容(加填充)*
"*WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)*"
...那么,为什么是对话框,以便大大高于它需要?
... so why is the dialog so much higher than it needs to be?
如果我更换布局高度
android:layout_height="200px"
它使一个正常的短对话,但我不希望使用显式像素高度(这不是好的做法)。如何使对话只是足够大的为它的内容?
it makes a properly short dialog but I don't want to use explicit pixel heights (it's not good practice). How do I make the dialog be just big enough for its content?
推荐答案
你有你的TextView的高度FILL_PARENT。是否有可能,这与RelativeLayout的高度结合,WRAP_CONTENT是推动其高度的最大尺寸是多少?如果你改变了TextView的高度为wrap_content会发生什么?
You have the height of your TextView to fill_parent. Is it possible that this, combined with the height of the RelativeLayout to wrap_content is pushing its height to the maximum size? What happens if you change the TextView height to wrap_content?
要添加,了Android SDK 说,一个RelativeLayout的子女不能有依赖在布局,如align_parent_bottom。我认为FILL_PARENT是一个依赖,因而是打破布局。
To add, the Android SDK says that children of a RelativeLayout can not have a dependency on the Layout, such as align_parent_bottom. I assume that fill_parent is a dependency and thus is breaking the layout.
相关推荐
最新文章