Android: location of activity as dialog
<p>I want to have a popup dialog in my app. The dialog is best done as an activity. I then use the "Theme.Dialog" in my manifest to cause the activity to behave as a dialog.  That works fine.</p>

<p>What doesn't seem to work is positioning the popup where I want it.</p>

<p>Here is a template of the popup, a circular menu that should be centered over the circular
button. Just a relative layout with six icons laid out around the "donut"
<img src="http://i.stack.imgur.com/ZQutx.png" alt="enter image description here"></p>

<p>What I want to do is have the popup displayed on the screen over one of several circular buttons. Depending on which button is pressed, I collect the X/Y location of the View (Button) that was pressed and send that over via bundle to the activity.  Then I want to position the dialog using the location of the pressed button and the size of the popup to place it, centered, over the button.</p>

<pre><code>public class WirelessDialog extends Activity {



@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.donut_dialogue);

    // get the layout of the dialog
    RelativeLayout rl = (RelativeLayout)findViewById(R.id.donut_layout);

    // get base image all other icons reside on and compute its haLf-width/height
    ImageView iv = (ImageView)findViewById(R.id.donut);
    int half_width = iv.getWidth() / 2 ;
    int half_height = iv.getHeight() / 2;


    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        int startX = extras.getInt("X");
        int startY = extras.getInt("Y");
        int endX = extras.getInt("XE");
        int endY = extras.getInt("YE");

        WindowManager.LayoutParams winParms = getWindow().getAttributes() ;
        int x = winParms.x;
        int y = winParms.y;
        Log.d("DIALOG", "Original x/y: " + x + " " + y);
        //int width = winParms.width;
        //int height = winParms.height;

        int xc = startX + (endX - startX + 1) / 2;
        int yc = startY + (endY - startY + 1) / 2;


        // new location of the dialog should be 1/2 the width and height of the donut subtracted
        // from the center of the button that was pressed.

        winParms.x = (xc - half_width);
        winParms.y = (yc - half_height);
        Log.d("DIALOG", "New    x/y: " + winParms.x + " " + winParms.y);
        getWindow().setAttributes(winParms);
    }

}
</code></pre>

<p>Setting the Layout Parameters only forces the dialog to the far right.  Originally, it's 
x/y location comes back as zero, but any non-zero number doesn't even place it where the locations indicate.</p>

<p>placing it at 0,0 is center of the screen, and setting the X/Y locations to be negative forces it to the uppper left.  The math isn't what I was expected based on the documentation</p>

<p>Anyone have an idea on what I should be doing to properly place this dialog window?
A typical example would be a button at (400, 470) on a 1280x800 screen tablet.</p>
