如何重力值的影响PopupWindow.showAtLocation()的安卓 [英] How do Gravity values effect PopupWindow.showAtLocation() in Android

查看:157
本文介绍了如何重力值的影响PopupWindow.showAtLocation()的安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不同的重力值的影响PopupWindow.showAtLocation()在Android的?

How do the different Gravity values effect PopupWindow.showAtLocation() in Android?

我无法找到PopupWindows showAtLocation和重力良好的文档。

I can't find good docs on PopupWindows showAtLocation and Gravity.

推荐答案

黑客攻击的几个小时尝试一些魔法数学计算中心,并尝试使用Gravity.TOP我发现了一个帖子,用来Gravity.CENTER对齐的观点后, 。我在这里收集我的调查结果中可以节省别人一些痛苦。

After hacking for a few hours trying some black magic maths to calculate centers and try to align the view using Gravity.TOP I found a post that used Gravity.CENTER. I'm collecting my findings here in the hopes it saves someone else some pain.

popupWindow.showAtLocation(anyViewOnlyNeededForWindowToken, Gravity.CENTER, 0, 0);

视图只需要为窗口令牌,其对位置没有其他的影响

The view is only needed for the window token, it has no other impact on the location.

重力告诉布局管理器从哪里开始的坐标系和如何对待这些坐标。我找不到文档,但黑客正显示出我说:

Gravity tells the layout manager where to start the coordinate system and how to treat those coordinates. I can't find the docs but hacking is showing me that:

  • CENTER使用弹出窗口的中间对齐到X,Y指定。所以0,0屏幕居中,对通知栏的大小没有调整。

  • BOTTOM使用弹出的底部对齐在x,y规定。所以,0,0具有弹出式底部与屏幕底部对齐。如果你想10px的填充,则Y = 10(不-10)移动弹出了屏幕10像素。

  • TOP使用弹出的顶部对准在x,y规定。所以,0,0有弹出顶部屏幕顶部对齐。如果你想10px的填充,则Y = 10。 注意如果您不是在全屏模式下,你还必须对通知栏的调整。
  • TOP uses the top of the popup to be aligned to the x,y specified. So 0,0 has the popup top aligned with the screen top. If you want 10px padding then y=10. NOTE If you are not in full screen mode then you must also make adjustments for the notification bar.

  • Gravity.LEFT和Gravity.RIGHT现在应该是显而易见的,我的例子图像他们是太大,以适应在屏幕上,以便它们将被锁定到屏幕大小减去我使用的填充。

这篇关于如何重力值的影响PopupWindow.showAtLocation()的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆