2011-11-23 104 views
1

我有一個PopupWindow填充LinearLayout。我instatiated像這樣我的彈出窗口:如何允許在Android的PopupWindow滾動

PopupWindow pw = new PopupWindow(layout, 450, 700, true); 
pw.showAsDropDown(layout, 80, 80); 

然而,當設備方向被切換爲橫向,在彈出的窗口被在底部切斷,我不能向下滾動。查看屏幕截圖: enter image description here

此彈出窗口下的佈局確實是可滾動的。那麼我怎樣才能讓彈出窗口滾動?

感謝, 伊戈爾

回答

3

LinearLayouts不滾動,所以不是在ScrollView封閉的LinearLayout。

+0

我在彈出下面有一個LinearLayout,而彈出窗口本身是在LinearLayout中。但是,當我嘗試將彈出窗口的代碼放在ScrollView中時,它只是放大並退出屏幕,但不滾動。奇怪... –

+0

除此之外,我不能有2個像這樣的ScrollViews。我收到一個錯誤:「java.lang.IllegalStateException:查看[email protected]已被添加到窗口管理器」 –

+0

您需要使用新的ScrollView,而不是重新使用現有的。 – kabuko

4

我這樣做是使用這個和工作:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_popup" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
<ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#444444"> 

</RelativeLayout> 
</ScrollView> 
</LinearLayout> 

我希望能對您有用。再見

+1

你的LinearLayout是無用的;通過用ScrollView替換根可以提高性能。 –