2016-07-04 46 views
0

我做了使用alertDialog Builder和asigned佈局,以這樣的:如何使用「wrap_content」佈局來檢索alertDialog的高度?

View view2 = LayoutInflater.from(getContext()).inflate(R.layout.information_dialog_layout, null); 
    AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.ert).create(); 
    alertDialog.setView(view2); 
    alertDialog.show(); 

,但將無法獲取在像素對話框高度,tryed「矩形」類,以及,但沒有幫助(可設置一個錯誤雖然)...? P.S我查閱了一些答案在這裏在計算器上類似的問題,但沒有對我的工作的:■

+0

其實'view2.getMeasuredHeight()'應該工作** **後顯示對話框。 –

+0

它沒有 - 獲得「0」:s – pb4now

+0

@SakchhamSharma答案有沒有例子,其中U使用Builder – pb4now

回答

0

你也許想使用

view2.getHeight(); 

,但結果將是不準確的。

alertDialog.getWindow().getDecorView().getHeight(); 

是因爲它會返回包括標題和按鈕對話的實際高度是更好的選擇。只需確保在您致電上述代碼時對話已成爲焦點。

More Info

+0

它也返回「0」:s - 當你說「有焦點」時,你的意思是把這個「之後alerDialog.show()? - 或者我誤解? – pb4now

相關問題