0

I've got a PopupWindow 'mPlayPopup' that I want to get displayed just below a certain View 'mPlayButton'. Here's how I do it:

 mPlayButton = new Button(activity);

 mPlayButton.setOnClickListener( new View.OnClickListener()
   {
   @Override
   public void onClick(View view)
        {
        mPlayPopup.showAsDropDown(view, 10, 10);
        mPlayPopup.update(view, mPlayPopupWidth, mPlayPopupHeight);
        }
   });

Simple - and it works in most cases, except when the app itself is in 'multi-window' or 'pop-up window' mode and its top-left corner is not the top-left corner of the screen.

In those cases, the mPlayPopup still pops up as if the top-left corner of the app was the top-left corner of the whole screen, which, if I open up my app in 'pop-up mode' and move it to the bottom of the whole screen - is well outside the window of the app itself.

How can I handle such case correctly?

Leszek
  • 1,181
  • 1
  • 10
  • 21

1 Answers1

0

I have also tried this:

    mPlayButton = new Button(activity);

    mPlayButton.setOnClickListener( new View.OnClickListener()
      {
      @Override
      public void onClick(View view)
        {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        int width  = view.getWidth();
        int height = view.getHeight();
        int x = location[0]+(width-mPlayPopupWidth)/2;
        int y = location[1]+height+margin;

        mPlayPopup.showAsDropDown(view);
        mPlayPopup.update(x,y,mPlayPopupWidth,mPlayPopupHeight);
        }
      });

The above, sadly, does not work everywhere. It does work on a physical LG K30 phone, Android emulators and another LG device. It does not work on a Samsung M12 physical phone though - it pops up the windows in unexpected places. It also does not work on a Xiaomi Mi 11 and, I expect, lots of other physical phones.

EDIT: after some more testing it's clear that neither the first code nor the second one really work in all cases.

EDIT: the first code works on Android 11. The second code works on Android 10 (most of the time). Neither works on Android 9 (although the second code works 'better').

Leszek
  • 1,181
  • 1
  • 10
  • 21