tags:

views:

58

answers:

1

In the Google Maps application, when you open the menu and click on "Directions", it pops up a dialog that is unique to Google Maps. It keeps the MapView in the background, but displays the search dialog from the top (or bottom, if you're on an old version of Android).

I was curious if anyone knew how they achieved this effect. I'm willing to create a custom Dialog, but it seems that Dialogs are designed to pop into the middle of the screen (any other types of dialogs are denied permission as system dialogs). What trick is Google Maps using?

+1  A: 

Just make your activity's root layout a FrameLayout or RelativeLayout (so your new view can overlap what's on screen). Then just add a layout with whatever you want as a child of that root layout (say, by inflating your desired dialog's XML into it when a button is clicked somewhere, either manually or using a ViewStub), and define a LayoutAnimation on the child before showing it.

For more on LayoutAnimations check out the API Demos app that ships with the Android SDK.

Yoni Samlan
How do you get the rest of the screen to grey out in the same way as when Dialogs are popped?
Daniel Lew
Ah - the easiest way to do that is to make your menu a new activity using the Transluscent theme -- http://developer.android.com/guide/topics/ui/themes.html#ApplyAThemeWhat I said about using a layout animation still applies, but you can skip the part about the framelayout.Alternatively, if you want to stay within the same Activity, you can stick a semitransparent layer in the FrameLayout above your main layout but below your new dialog (ex. a child FrameLayout set to fill_parent with a background of "#cddd" or the like).
Yoni Samlan
The ultimate solution was more involved than I expected, but is rooted in this answer. Thanks. :)
Daniel Lew