Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with the ICS Holo Dialog theme?

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

like image 326
Michell Bak Avatar asked Feb 06 '12 16:02

Michell Bak


1 Answers

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.

like image 193
Sparky Avatar answered Oct 05 '22 21:10

Sparky