I want to create a dialog which appears when user presses a button. (In fact it's kind of a volume control appearing when user clicks the button with headphones)
I have a layout file for dialog (with height dependent on content) and in onCreate method I try to set gravity top|right and custom margin (the same as my button has).
this.getWindow().setGravity(Gravity.TOP | Gravity.RIGHT);
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.x = x;
lp.y = y;
But what I get is just a centered dialog on the right (not top-right!) without any margin.
In other words I'd like to draw my dialog with custom layout at specified point on the screen.