0

I'm using PopupWindow class to show a popup above a view. In this popup, I set a contentview with a navigate (a triangle show the position of a clicked view).

The image can be demonstrated as below:

  ***************
  * popup       *
  ***   *********
     *  *        
       *
    *******
    *view *
    *******  

I want to display the triangle to correct position (the center X of the view), My formule is:

The X triangle offset  = viewLeft - popupLeft.

I can calculate the view left but can not calculate the popup left. The getLocationOnScreen return 0 because the popup is not rendered.

Do you have any idea?. Please share. Thanks. :d

Paul
  • 950
  • 2
  • 12
  • 28

1 Answers1

1

The "popup" has not been drawn where you are trying to size it. You must wait until it has been placed on the screen (or is about to be placed). You can do this in one of several ways:

ViewTreeObserver Overriding onSizeChanged Overriding onWindowFocusChanged

See this post: getWidth() and getHeight() of View returns 0

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36