为什么弹出视图会折叠其他视图?

时间:2014-06-03 08:38:30

标签: android android-layout android-popupwindow

我使用弹出窗口显示日历视图,同时显示弹出窗口,它会折叠整个视图,即它会扰乱旁边的视图,它不会像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);

        }

    };


    }

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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);
    }