How to allow scrolling in Android's PopupWindo

2019-08-01 02:10发布

问题:

I have a PopupWindow that is populated with a LinearLayout. I instatiated my popup window like this:

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

However, when the device orientation is switched to landscape, the popup window gets cut off at the bottom and I cannot scroll down. See the screen capture:

The layout underneath this popup is indeed scrollable. So how can I make the popup scrollable?

Thanks, Igor

回答1:

LinearLayouts aren't scrollable, so instead enclose the LinearLayout in a ScrollView.



回答2:

I do it using this and worked:

<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>

I hope it can be useful for you. Bye