16

I am using PopupWindow with showAsDropDown(anchor). When the anchor is at the top of the screen it works fine, but when at the bottom of the screen nothing shows up. According to the documentation for PopupWindow.showAsDropDown() this should work:

http://developer.android.com/reference/android/widget/PopupWindow.html#showAsDropDown%28android.view.View%29

"Display the content view in a popup window anchored to the bottom-left corner of the anchor view. If there is not enough room on screen to show the popup in its entirety, this method tries to find a parent scroll view to scroll. If no parent scroll view can be scrolled, the bottom-left corner of the popup is pinned at the top left corner of the anchor view."

Presumably, the popup is always anchored to the bottom-left corner of the anchor view. How do I fix this?

2

2 Answers 2

4

You can try this .. may be it helps

mWindow.showAtLocation(mRootView, Gravity.BOTTOM|Gravity.LEFT, 0, distanceFromTop);
3
  • 2
    what is "distanceFromTop"? from the top of the screen? How would you calculate this?
    – Kenny
    Mar 17, 2017 at 1:34
  • @GOLDEE what is distanceFromTop? is it the anchorView?
    – Jack
    Oct 12, 2018 at 19:48
  • Its margin from the mRootView or you can say achorView
    – GOLDEE
    Nov 26, 2018 at 12:49
0

I know this is an old thread, but I thought I'd post my solution. It looks like you have to explicitly set the width and height of the popupWindow before calling showAsDropDown().

    menuLayout.measure( View.MeasureSpec.UNSPECIFIED, 
                        View.MeasureSpec.UNSPECIFIED );
    int height = menuLayout.getMeasuredHeight();
    int width = menuLayout.getMeasuredWidth();
    popupMenu.setWidth( width );
    popupMenu.setHeight( height );

    popupMenu.showAsDropDown( clickedCell );

In this case menuLayout is the view displayed in the popupWindow.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.