0

I'm using the popup window to show the calendar view ,while showing the popup window it collapses the whole view ,i.e it is disturbing the view next to it ,it doesn't popup like Spinner(spinner adapter view). what may be problem , here my code

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);

        }

    };


    }
Strawberry
  • 667
  • 2
  • 10
  • 24

2 Answers2

0

these are some tips for PopupWindow pop position,

  // 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);
Sree
  • 3,136
  • 2
  • 31
  • 39
0

Try below code, its working for me:

 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);
    }
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44