Search code examples
androidandroid-popupwindow

Popup window android is not setting above view in android?


At the bottom right of the page I have a view on whose click I am opening the pop up window. But it opens up overlapping the view. I want it to open above the view.

Below are the screenshots.

enter image description here

enter image description here

And below is my code Creating the window as

seasonEpisodePopUpWindow = new PopupWindow(this);
        seasonEpisodePopUpWindow.setContentView(seasonEpisodeView);
        seasonEpisodePopUpWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        seasonEpisodeView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        seasonEpisodePopUpWindow.setWidth(seasonEpisodeView.getMeasuredWidth() * 2);

And this is how I am opening the pop up window

int[] viewLocation = new int[2];
    anchorView.getLocationOnScreen(viewLocation);
    if (!seasonEpisodePopUpWindow.isShowing()) {
        seasonEpisodePopUpWindow.showAtLocation(anchorView, Gravity.TOP, viewLocation[0], viewLocation[1] - anchorView.getHeight());
    }

How do I open the view above my view?


Solution

  • was able to solve this with below

    seasonEpisodePopUpWindow.showAtLocation(anchorView, Gravity.BOTTOM, viewLocation[0], anchorView.getHeight());