Android - PopupWindow above a specific view

前端 未结 8 466
孤城傲影
孤城傲影 2020-12-30 23:50

I am developing an application for Android and I am using a popup window when the user clicks a specific menu bar object(consisting of small images lined up horizontally) on

相关标签:
8条回答
  • 2020-12-31 00:14

    Sample example:

    ScrollView scrollView = new ScrollView(context);
    popupWindow.setContentView(scrollView);
    scrollView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),                 
    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    int he=scrollView.getMeasuredHeight();
    popupWindow.showAsDropDown(items,0, -items.getHeight()-he);
    
    0 讨论(0)
  • 2020-12-31 00:15

    The one you want to use is showAtLocation(...). You specify the anchor view (the one the user clicks), and position it relative to that via the gravity parameter and offsets. Think of the gravity parameter like the PopupWindow is almost like a child view and the parent view is like a container layout.

    You should be able to put Gravity.LEFT | Gravity.TOP as the parameter.

    0 讨论(0)
提交回复
热议问题