lomza
lomza

Reputation: 9746

Align Android activity

Is there any possibility in Android to align a dialog Activity (activity with a dialog theme) at the bottom? By default, it is displayed in the middle of the screen. I haven't found any information on that... Thanks.

Upvotes: 2

Views: 246

Answers (2)

MKJParekh
MKJParekh

Reputation: 34311

I didn't tried but searching on google found this...does this help you getWindow().setAttributes() , I hope this will help you.

content of the link (if it doesn't work) :-

You can call getWindow().getAttributes() to retrieve the WindowManager.LayoutParams for the window. This has the following fields involving window placement:

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 your desired changes, use getWindow().setAttributes() to install the new values.

Note that, though you can force a specific size through the width and height fields, in general the correct way to do this is let the window do its normal layout and determine the window size automatically that way. If you have a single view in the dialog that wants a fixed size such as 300x200, implement View.onMeasure() to call setMeasuredDimension(300, 200). Then when the view hierarchy layout happens, the dialog window will be given a size that ensures your view is that dimension (probably making the actual window larger to take into account the dialog frame and decoration).

http://code.google.com/android/reference/android/view/View.html#onMeasure(int,%20int)

Upvotes: 1

Aleks G
Aleks G

Reputation: 57346

This is not exactly what you are doing, but I had a similar problem where I needed to display a dialog from an activity - at the bottom of the screen. The trick was to use WindowManager.LayoutParams. Here's what my onPrepareDialog looks like:

public void onPrepareDialog(int dialog, Dialog dlg) {
    Window window = dlg.getWindow();
    WindowManager.LayoutParams wlp = window.getAttributes();
    switch (dialog) {
    case DIALOGUE_LOADING_PLEASE_WAIT:
        wlp.gravity = Gravity.BOTTOM;
        window.setAttributes(wlp);
        break;
    default:
        break;
    }
}

Upvotes: 1

Related Questions