2011-11-24 58 views
2

Android有沒有可能在底部對齊Activity對話框(活動和對話框主題)?默認情況下,它顯示在屏幕中間。我還沒有找到任何有關這方面的信息......謝謝。對齊Android活動

回答

1

這不完全是你在做什麼,但我有一個類似的問題,我需要顯示一個活動的對話框 - 在屏幕的底部。訣竅是使用WindowManager.LayoutParams。這裏是我的onPrepareDialog是什麼樣子:

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; 
    } 
} 
+0

謝謝!它完美的作品!我想這對任何一種活動或對話都是正確的。 – lomza

1

我沒試過,但搜索對谷歌發現這...這是否幫助你getWindow().setAttributes(),我希望這會幫助你。

內容的鏈接(如果它不工作): -

你可以叫getWindow()的getAttributes()來檢索 WindowManager.LayoutParams的窗口。這有以下 領域涉及窗口位置:

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

完成所需更改後,U se getWindow()。setAttributes()到 安裝新的值。

需要注意的是,雖然你可以強制特定的大小,通過寬度和高度 領域,一般正確的方法做,這是我們的窗口 做正常的佈局,並自動確定窗口大小 方式。如果對話框中的單個視圖需要固定尺寸 (如300x200),請執行View.onMeasure()以調用 setMeasuredDimension(300,200)。然後,當視圖層次佈局發生時,對話框窗口將被賦予一個尺寸,以確保您的視圖 是該尺寸(可能會使實際窗口更大,以將對話框和裝飾考慮在內,從而將 考慮在內)。

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