<bdo id='QI1Sq'></bdo><ul id='QI1Sq'></ul>

      <i id='QI1Sq'><tr id='QI1Sq'><dt id='QI1Sq'><q id='QI1Sq'><span id='QI1Sq'><b id='QI1Sq'><form id='QI1Sq'><ins id='QI1Sq'></ins><ul id='QI1Sq'></ul><sub id='QI1Sq'></sub></form><legend id='QI1Sq'></legend><bdo id='QI1Sq'><pre id='QI1Sq'><center id='QI1Sq'></center></pre></bdo></b><th id='QI1Sq'></th></span></q></dt></tr></i><div id='QI1Sq'><tfoot id='QI1Sq'></tfoot><dl id='QI1Sq'><fieldset id='QI1Sq'></fieldset></dl></div>

    1. <tfoot id='QI1Sq'></tfoot>

      <legend id='QI1Sq'><style id='QI1Sq'><dir id='QI1Sq'><q id='QI1Sq'></q></dir></style></legend>

      <small id='QI1Sq'></small><noframes id='QI1Sq'>

        显示一个 PopupWindow 集中

        Show a PopupWindow centralized(显示一个 PopupWindow 集中)

          <small id='3BBSo'></small><noframes id='3BBSo'>

            <bdo id='3BBSo'></bdo><ul id='3BBSo'></ul>
            <i id='3BBSo'><tr id='3BBSo'><dt id='3BBSo'><q id='3BBSo'><span id='3BBSo'><b id='3BBSo'><form id='3BBSo'><ins id='3BBSo'></ins><ul id='3BBSo'></ul><sub id='3BBSo'></sub></form><legend id='3BBSo'></legend><bdo id='3BBSo'><pre id='3BBSo'><center id='3BBSo'></center></pre></bdo></b><th id='3BBSo'></th></span></q></dt></tr></i><div id='3BBSo'><tfoot id='3BBSo'></tfoot><dl id='3BBSo'><fieldset id='3BBSo'></fieldset></dl></div>
            • <legend id='3BBSo'><style id='3BBSo'><dir id='3BBSo'><q id='3BBSo'></q></dir></style></legend>
                <tfoot id='3BBSo'></tfoot>
                  <tbody id='3BBSo'></tbody>
                1. 本文介绍了显示一个 PopupWindow 集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have some popups on my app, it's fullscreen and the following code:

                      content.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                              LayoutParams.WRAP_CONTENT));
                      content.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                      int screenWidth = windowManager.getDefaultDisplay().getWidth();
                      int screenHeight = windowManager.getDefaultDisplay().getHeight();
                      int x = screenWidth / 2 - content.getMeasuredWidth() / 2;
                      int y = screenHeight / 2 - content.getMeasuredHeight() / 2;
                      window.showAtLocation(content, Gravity.NO_GRAVITY, x, y);
                  

                  Make the window show centered.

                  But I have another Activity which is not fullscreen, when the popup opens it's right-down from where it's need to be.

                  Trying to figure out why this happens, I think the showAtLocation shows it's relative to the current Activity, but I need to show it relative to the display.

                  How can I do that? Or there's a simpler way to just the popup just centered?

                  解决方案

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

                  This will center your view.

                  It took me 2 hours of pain to figure this out. I didn't need any black magic maths to handle this.

                  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 uses the middle of the popup to be aligned to the x,y specified. So 0,0 is screen centered
                  • BOTTOM uses the bottom of the popup to be aligned to the x,y specified. So 0,0 has the popup bottom aligned with the screen bottom. If you want 10px padding then y=10 (not -10) to move the popup up the screen 10 pixels.

                  I wrote this up over here Android PopupWindow.showAtLocation() and effects of Gravity

                  这篇关于显示一个 PopupWindow 集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  Android copy image from gallery folder onto SD Card alternative folder(Android将图像从图库文件夹复制到SD卡替代文件夹)
                  Is there a tool to find unused resources in an Android project?(是否有工具可以在 Android 项目中查找未使用的资源?)
                  <tfoot id='005ag'></tfoot>
                  <i id='005ag'><tr id='005ag'><dt id='005ag'><q id='005ag'><span id='005ag'><b id='005ag'><form id='005ag'><ins id='005ag'></ins><ul id='005ag'></ul><sub id='005ag'></sub></form><legend id='005ag'></legend><bdo id='005ag'><pre id='005ag'><center id='005ag'></center></pre></bdo></b><th id='005ag'></th></span></q></dt></tr></i><div id='005ag'><tfoot id='005ag'></tfoot><dl id='005ag'><fieldset id='005ag'></fieldset></dl></div>
                  <legend id='005ag'><style id='005ag'><dir id='005ag'><q id='005ag'></q></dir></style></legend>

                      <bdo id='005ag'></bdo><ul id='005ag'></ul>

                            <tbody id='005ag'></tbody>
                        • <small id='005ag'></small><noframes id='005ag'>