2012-07-09 77 views
3

我有一個彈出窗口,其中包含一個滾動視圖中的幾個EditTexts。 當我點擊一個EditText時,它在後臺向上滾動視圖,而不是彈出窗口,因此鍵盤會阻止EditText。安卓彈出與EditText,鍵盤塊文本,背景滾動

任何想法?

PopupWindow popUp = new PopupWindow(this); 
popUp.update(0, 0, display.getWidth(), display.getHeight()); 
popUp.setFocusable(true); 

LinearLayout llh = new LinearLayout(this) 
llh.setOrientation(LinearLayout.HORIZONTAL); 
ScrollView sv = new ScrollView(this); 

EditText e1,e2,e3... 
llh.addView(e1);  
llh.addView(e2);  
llh.addView(e3); 
... 
sv.addView(llh); 
popUp.setContentView(llh); 
popUp.showAtLocation(llh, Gravity.BOTTOM, 0, 0); 

這是從一個視圖「啓動」,它也包含一個ScrollView。

如果有解決方法,這將是很好的。

回答

1

我遇到了與您相同的問題,爲了解決這個問題,我創建了自定義Dialog並使用自定義主題(在以下示例中爲R.style.ThemeDialogCustom)。我還設置了dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)dialog.setCanceledOnTouchOutside(true);,我用setContentView設置了自定義佈局。是這樣的:

Dialog dialog = new Dialog(activityContext, R.style.ThemeDialogCustom); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setCanceledOnTouchOutside(true); 
dialog.setContentView(R.layout.custom_dialog_layout); 

換言之,上述片的代碼試圖immitate一個PopupWindow的行爲。

編輯爲了清楚的目的,如果你需要訪問對話框的自定義佈局中定義的視圖,您可以像這樣訪問:

EditText e1 = (EditText) dialog.findViewById(R.id.e1); 

希望有所幫助。

+0

將嘗試與我的自定義對話框之一,thx – stefple 2012-07-09 21:00:43

+0

工程,再次感謝 – stefple 2012-07-09 22:57:18

+0

很高興我可以幫助:-) – Angelo 2012-07-10 04:58:47