So I created a custom popup menu or tooltip that I want to appear in a particular location but I found that the popup menu appears in a different location depending on screen resolution, is there some calculation I need to take into consideration to make sure that the popup menu/tooltip appears on the same location no matter what screen resolution the tablet is?
Asked
Active
Viewed 180 times
0
-
I'm using the function showAtLocation to display the item at a particular location on screen. – Eric Bergman Jul 03 '13 at 16:42
1 Answers
0
If you calculating offset in pixels - you obviously need to take screen density in consideration. I would look at DisplayMetrics
first (in particular scaledDensity
field) .
Here is how I get DisplayMetrics
:
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
yourOffsetPX *= metrics.scaledDensity;

Pavel Dudka
- 20,754
- 7
- 70
- 83
-
I have something like this: int[] location = new int[2]; view.getLocationOnScreen(location); Rect anchorRect = new Rect(location[0], location[1], location[0] + view.getWidth(), location[1] + view.getHeight()); yPos = anchorRect.top; – Eric Bergman Jul 03 '13 at 19:04
-
if you are anchoring you popup to some other view (that's how I understand your snippet), then I would assume your view is at wrong position. In this case it depends how you add an anchor view to the layout (via XML or code) – Pavel Dudka Jul 03 '13 at 21:49