Android popup window not filling screen size?

Here you can’t use layout which is in your popup window xml. You have to use any View from main layout. Right now I am using FloatingButton as a View to showAtLocation.

fabButton = (ImageButton) findViewById(;
            fabButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(final View v) {

 private void initiatePopupWindow(View v) {
            try {
                //We need to get the instance of the LayoutInflater, use the context of this activity
                LayoutInflater inflater = (LayoutInflater) ProfileView.this
                //Inflate the view from a predefined XML layout
                View layout = inflater.inflate(R.layout.popup,
                        (ViewGroup) findViewById(;
                // create a 300px width and 470px height PopupWindow
                pw = new PopupWindow(layout, 300, 470, true);
                // display the popup in the center
                pw.showAtLocation(v, Gravity.CENTER, 0, 0);

                TextView mResultText = (TextView) layout.findViewById(;
                Button cancelButton = (Button) layout.findViewById(;

            } catch (Exception e) {

Leave a Comment