What's wrong with the ICS Holo Dialog theme?
Asked Answered
E

4

18

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) enter image description here

The incorrect way (Ice Cream Sandwich) enter image description here

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...

enter image description here

Equilibrist answered 6/2, 2012 at 16:16 Comment(6)
That does seem weird. This is a shot in the dark, but sometimes I'll experience weird graphical glitches in my app after changing the Build Target. I have no idea why, but cleaning the project will always fix them. Like I said, shot in the dark, but it may be that simple.Rocca
Thanks, just tried that again, but didn't seem to have any effect. I've just updated my question again - it seems like it's happening between 894 and 895 dp of width.Equilibrist
Are your screen shots taken using two separate devices? Your post assumes that this behavior always works correctly on HoneyComb but not on ICS, but is it possible that the problem you are having is entirely dependent on the size of the screen? If not, then you might consider creating two AVDs (one running 3.0 and another running 4.0) with the exact same screen size and testing it with the two to determine if the problem is in fact dependent on the Android SDK version number.Oops
@AlexLockwood Two different devices, but they're using the exact same screen size (xlarge, mdpi). I've also tried with the SDK to recreate identical AVDs, and it is in fact dependent on the version of Android. As you can see below, Sparky, who is on the Android dev team, is experiencing the same issue, and this question has been receiving a lot of attention lately, so my guess is that many other devs are noticing the bug as well.Equilibrist
Did you ever figure this one out? I'm seeing the same broken-ness on ICS but not on Jellybean so I figure they've fixed it now. But I'm wondering if there's a workaround to deal with this issue on ICS.Roughneck
@antrix Nope, sorry. Didn't find a solution :-(Equilibrist
F
6

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 from Holo.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.

Faddist answered 4/4, 2012 at 12:12 Comment(2)
Thanks, would be excellent! Didn't even know of the Holo.Dialog.FixedSize theme.Equilibrist
I'm seeing this same issue: An activity themed using the Theme.Holo.Light.Dialog.NoActionBar theme behaves correctly on JellyBean but has the above 'excess size' issue on ICS.Roughneck
E
1

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.

Equilibrist answered 11/2, 2012 at 17:27 Comment(0)
W
0

All version of Android ignore the width/height of a Dialog themed layout xml.

To fix this, after calling:

setContentView(R.layout.contacts_preferences);

add a line:

getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

or WRAP_CONTENT for your needs.

Wolfgang answered 3/5, 2012 at 7:38 Comment(0)
Z
0

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.

Zalea answered 19/6, 2013 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.