Dialog Box Location

I have activity with MapView. I have overlays on this map, and I would like to position the hover dialog above the element if it is listening.

I already have my own custom dialog box in which I was compiled with my own layout and customizable background. My only problem is how to tell Android where (in terms of x, y) to place the dialog.

This is even more difficult, since knowing what the dialogue x, y is. First I need to know the width and height of the dialog after the measurement (since I need to calculate the position relative to my overlay).

+5
source share
1 answer

A quick Google search came up with the following :

You can call getWindow (). getAttributes () to get the WindowManager.LayoutParams window for the window. This field contains the following fields:

http://code.google.com/android/reference/android/view/ViewGroup.LayoutParams.html#width http://code.google.com/android/reference/android/view/ViewGroup.LayoutParams.html#height http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#gravity http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#x http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#y

After making the necessary changes, use getWindow (). setAttributes () to set new values.

Note that while you can force a specific size across the width and height fields, in general, the correct way to do this is to let the window execute a normal layout and automatically determine the size of the window. If you have one view in a dialog that requires a fixed size, such as 300x200, implement View.onMeasure () to call setMeasuredDimension (300, 200). Then, when the layout of the view hierarchy is expanded, the dialog will be set to a size that ensures that your view is that size (probably making the actual window larger to take into account the frame of the dialog and decoration).

Hope this helps.

+11
source

All Articles