-1

我是安卓新手。这是我的问题。有没有弹出窗口可以在android中移动?如何实现弹出窗口或其他可以下药的对话框。而且这个弹窗可以不挡住其他的窗口吗?当它弹出时,我仍然可以在主窗口中使用其他功能。

先感谢您

4

2 回答 2

0

为此目的使用 PopupWindow 类,请参阅以下链接: http ://www.mobilemancer.com/2011/01/08/popup-window-in-android/

于 2012-05-08T07:20:11.683 回答
0

这是我工作的示例代码,我做一些评论来声明它是如何工作的

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              // your custom view
            View popView = inflater.inflate(R.layout.pop_view, null);
             // initialise your pop window  
             // take custom view , with specific width , height
           PopupWindow popupWindow = new PopupWindow(popView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
            ImageView imageview = (ImageView) popView.findViewById(R.id.imageview);
            Button dismiss = (Button) popView.findViewById(R.id.disbutton);
            imageview.setImageURI(imagePath);

    // button used to open pop window 
            popupWindow.showAsDropDown(ChooseFile, 50, -30);

          // here is the part related to move popwindow    
            popView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent event) {

                    int orgX = 0, orgY = 0;
                    int offsetX, offsetY;


                    switch (event.getAction()) {

                        case MotionEvent.ACTION_DOWN:

                            orgX = (int) event.getRawX();
                            orgY = (int) event.getRawY();
                            break;

                        case MotionEvent.ACTION_MOVE:
                            offsetX = (int) event.getRawX() - orgX;
                            offsetY = (int) event.getRawY() - orgY;
                           // update popwindow postion , -1 set for width & height to make it fixed not changed 
                            popupWindow.update(offsetX, offsetY, -1, -1);
                            break;

                    }

                    return true;
                }
            });

            dismiss.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  // if you want dismiss your pop window 
                    popupWindow.dismiss();
                }
            });


        }
于 2015-07-30T14:37:51.013 回答