ICS Holo Dialog 主题有什么问题?
我在 Ice Cream Sandwich 中使用 Holo Dialog 主题 (@android:style/Theme.Holo.Dialog
) 的活动时遇到了一些奇怪的问题。
看起来他们忽略了布局并填充了整个屏幕,而不是 XML 布局中的布局宽度和高度。相同的布局在 Honeycomb 中可以按预期工作,但在 Ice Cream Sandwich 上则不然。
示例:
正确的方法(蜂巢)
错误方法(冰淇淋三明治)
两个设备都运行完全相同版本的应用程序,并且使用完全相同的布局。这是有问题的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="940dp"
android:layout_height="600dp"
android:layout_margin="10dp" >
<GridView
android:id="@+id/gridView1"
android:layout_width="940dp"
android:layout_height="600dp"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
对于如何解决这个问题有什么想法吗?我的基于 ICS 的 Galaxy Nexus 上也出现了类似的问题,它完全忽略高度和宽度的 match_parent
标签。 ICS 中的对话框主题是否损坏?
更新:
我做了一些更多的测试,看起来 894dp 或更少的宽度会产生“正确”的外观,但如果我将宽度设置为 895dp 或更大,它将是不正确的外观。模拟器的行为方式相同。这非常奇怪...
I've come across a bit of a weird issue with activities using the Holo Dialog theme (@android:style/Theme.Holo.Dialog
) in Ice Cream Sandwich.
It seems like they ignore their layouts and fill the entire screen instead of the layout width and height from their XML layouts. The same layouts are working as expecting in Honeycomb, but not on Ice Cream Sandwich.
Example:
The correct way (Honeycomb)
The incorrect way (Ice Cream Sandwich)
Both devices are running the exact same version of the application, and are using the exact same layout. Here's the layout in question:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="940dp"
android:layout_height="600dp"
android:layout_margin="10dp" >
<GridView
android:id="@+id/gridView1"
android:layout_width="940dp"
android:layout_height="600dp"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
Any ideas to how this can be solved? A similar issue occurs on my ICS-based Galaxy Nexus, which completely ignore the match_parent
tag for height and width. Is the dialog theme broken in ICS?
Update:
I've done some more testing, and it seems like 894dp of width or less will produce the "correct" look, but if I set the width to 895dp or more, it'll be the incorrect look. The emulator's acting the same way. This is extremely weird...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为 ICS 并不鼓励对话。事实上,他们在 Android Design 上有一个完整的 页面。事实是 DialogFragment (甚至在 Android 支持库)优于旧版 对话框。
我证实了您对对话框弹出到全屏的观察,但该行为取决于设备。在我的 Xoom 平板电脑上,它发生在 915dp,而不是 895。在我的 Galaxy Nexus 上,它发生在 444dp。而在我的 Galaxy Tab 10.1 上,这种情况根本没有发生。
如果深入研究源代码,您会发现有一个 Dialog 主题,它源自用于较小屏幕的
Holo
和用于较大屏幕的Holo.Dialog.FixedSize
。我本以为这是基于显示尺寸,而不是布局尺寸,但也许我错了。我会尝试找出导致跳跃的原因。I don't think it is true that ICS discourages dialogs. Indeed, they have a whole page at Android Design. What is true is that DialogFragment (which is even provided in the Android Support library) is preferred over the legacy Dialog.
I corroborate your observation about the dialog popping to full-screen, but the behavior is device-dependent. On my Xoom tablet it happens at 915dp, not 895. On my Galaxy Nexus, it happens at 444dp. And on my Galaxy Tab 10.1, it does not happen at all.
If you dig into the source, you can see that there is a Dialog theme that is descended from
Holo
for smaller screens and fromHolo.Dialog.FixedSize
for larger ones. I would have expected this to be based on display size, not layout size, but perhaps I would be mistaken. I'll try to figure out what causes the jump.我自己找不到答案,所以我最终放弃了对话框主题,而是使用全角标准主题布局。我认为 ICS 不鼓励使用对话框,所以也许这就是它被改变的原因。
I couldn't find an answer for this myself, so I eventually dropped the dialog theme and instead used a full-width standard theme layout. I think ICS discourages the use of dialogs, so maybe that's why it's changed.
所有版本的 Android 都会忽略 Dialog 主题布局 xml 的宽度/高度。
要解决此问题,请在调用后
添加一行:
或
WRAP_CONTENT
以满足您的需要。All version of Android ignore the width/height of a Dialog themed layout xml.
To fix this, after calling:
add a line:
or
WRAP_CONTENT
for your needs.尝试将 LinearLayout 替换为relativelayout。这样就可以解决问题了:)
不知怎的,当在对话框中显示时,LinearLayouts 总是填充屏幕。相对布局则不然。
Try swapping your LinearLayout for a RelativeLayout. That will do the trick :)
Somehow LinearLayouts always fills the screen when displayed in a dialog. RelativeLayouts don't.