Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android dialog activity position

I created an non-maximized activity using android:theme="@android:style/Theme.Dialog" to make it looks like a dialog. I need to change the position of the activity on screen but I didn't find how to do this...

like image 705
Arutha Avatar asked Jan 29 '10 16:01

Arutha


People also ask

When a dialog is displayed on top of your activity?

when a dialog is shown or it's window comes visible on top of an existing activity, then it overrides partial the activity window so existing activity will move to partially invisible state and you will get call to onPause() from ActivityThread. but to be sure we also need to consider here a one think...

What are dialog in android?

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.


1 Answers

To change the position (with the theme set to Theme.Dialog), you can override the gravity, size and coordinates of the LayoutParams of your activity's decor view after it has been attached to the window. Here's an example:

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    View view = getWindow().getDecorView();
    WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
    lp.gravity = Gravity.LEFT | Gravity.TOP;
    lp.x = 10;
    lp.y = 10;
    lp.width = 300;
    lp.height = 300;
    getWindowManager().updateViewLayout(view, lp);
}
like image 52
Joe Avatar answered Oct 02 '22 01:10

Joe