0

我正在使用弹出窗口来显示日历视图,在显示弹出窗口时它会折叠整个视图,即它会干扰旁边的视图,它不会像 Spinner(微调器适配器视图)那样弹出。可能是什么问题,这是我的代码

private void showPopup(Context context,LinearLayout Parent,final View v) {


    LayoutInflater layoutInflater = (LayoutInflater)context
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layout = layoutInflater.inflate(R.layout.popupl,Parent,true);
    // Creating the PopupWindow
    final PopupWindow popupWindow = new PopupWindow(
               layout,700,700);

   popupWindow.setFocusable(true);    
   popupWindow.setContentView(layout);
   popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
   popupWindow.setWidth(250);


    new Runnable(){
        @Override
        public void run() {

            popupWindow.showAsDropDown(v, -5, 0);

        }

    };


    }
4

2 回答 2

0

这些是 PopupWindow 弹出位置的一些提示,

  // to themselves as the Anchor, not offset

            popupWindow.showAsDropDown (v);

// to themselves as the Anchor, offset (screenWidth-dialgoWidth) / 2, 0) - button just below  

       popupWindow.showAsDropDown (v, (screenWidth-dialgoWidth) / 2, 0);

// to the center of the screen as a reference, not offset

    popupWindow.showAtLocation (findViewById (R.id.layout), Gravity.CENTER, 0, 0); 


// to the lower-left corner of the screen as a reference, the offset (screenWidth the-dialgoWidth) / 2, 0) - the bottom of the screen central  


popupWindow.showAtLocation (findViewById (R.id.layout);
于 2014-06-03T08:51:30.127 回答
0

试试下面的代码,它对我有用:

 int popupWidth = getDeviceWidth() - convertSizeToDeviceDependent(50);
            int popupHeight = getDeviceHeight() - convertSizeToDeviceDependent(180);


            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = layoutInflater.inflate(R.layout.YOUR LAYOUT, viewGroup);

            popup = new PopupWindow(this);
            popup.setContentView(layout);
            popup.setWidth(popupWidth);
            popup.setHeight(popupHeight);
            popup.setFocusable(true);
            popup.setBackgroundDrawable(new BitmapDrawable(getResources()));
            popup.showAtLocation(layout, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);

public int convertSizeToDeviceDependent(int value) {
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        return ((dm.densityDpi * value) / 160);
    }
于 2014-06-03T08:53:46.267 回答