Android PopupWindow showAsDropDown() not working properly

◇◆丶佛笑我妖孽 提交于 2019-12-04 23:31:48

You can try this .. may be it helps

mWindow.showAtLocation(mRootView, Gravity.BOTTOM|Gravity.LEFT, 0, distanceFromTop);

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!