• <tfoot id='3XNPS'></tfoot>

    <legend id='3XNPS'><style id='3XNPS'><dir id='3XNPS'><q id='3XNPS'></q></dir></style></legend>

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

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

      1. 弹出窗口以在片段中显示一些东西

        Pop up window to display some stuff in a fragment(弹出窗口以在片段中显示一些东西)
          <tbody id='SwoCG'></tbody>

              • <bdo id='SwoCG'></bdo><ul id='SwoCG'></ul>

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

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

                  本文介绍了弹出窗口以在片段中显示一些东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试制作类似于弹出窗口的东西,当单击片段中的视图时会出现该窗口.我希望这个弹出窗口或其他任何东西不会像对话框片段那样使片段变暗.而且我还希望弹出窗口位于单击视图的位置.如果它有自己的活动和布局会很好,这样我就可以在其中进行一些自定义更改.可以给我看一些示例代码吗?

                  I am trying to make something like a pop-up window, that would appear when clicked on a view in a fragment. I want this pop-up window or whatever, to not make the fragment dark, like a Dialog Fragment does. And I also want the pop up to be positioned where the view is clicked. Would be good if it has its own activity and layout so I can do some custom changes in it. Can you plese show me some sample code?

                  推荐答案

                  以下内容应符合您的规范.从分配给视图的 OnClickListeneronClick(View v) 内部调用此方法:

                  The following should work perfect in accordance with your specification. Call this method from inside onClick(View v) of OnClickListener assigned to the View:

                  public void showPopup(View anchorView) {
                  
                      View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);
                  
                      PopupWindow popupWindow = new PopupWindow(popupView, 
                                             LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                  
                      // Example: If you have a TextView inside `popup_layout.xml`    
                      TextView tv = (TextView) popupView.findViewById(R.id.tv);
                  
                      tv.setText(....);
                  
                      // Initialize more widgets from `popup_layout.xml`
                      ....
                      ....
                  
                      // If the PopupWindow should be focusable
                      popupWindow.setFocusable(true);
                  
                      // If you need the PopupWindow to dismiss when when touched outside 
                      popupWindow.setBackgroundDrawable(new ColorDrawable());
                  
                      int location[] = new int[2];
                  
                      // Get the View's(the one that was clicked in the Fragment) location
                      anchorView.getLocationOnScreen(location);
                  
                      // Using location, the PopupWindow will be displayed right under anchorView
                      popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, 
                                                       location[0], location[1] + anchorView.getHeight());
                  
                  }
                  

                  评论应该很好地解释了这一点.anchorViewonClick(View v) 中的 v.

                  The comments should explain this well enough. anchorView is the v from onClick(View v).

                  这篇关于弹出窗口以在片段中显示一些东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 项目中查找未使用的资源?)

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

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

                    • <bdo id='lHU9S'></bdo><ul id='lHU9S'></ul>

                      • <tfoot id='lHU9S'></tfoot>

                        1. <legend id='lHU9S'><style id='lHU9S'><dir id='lHU9S'><q id='lHU9S'></q></dir></style></legend>
                              <tbody id='lHU9S'></tbody>