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(R.id.activity_profileView_FAB); fabButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { initiatePopupWindow(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 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //Inflate the view from a predefined XML layout View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_element)); // 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(R.id.server_status_text); Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button); cancelButton.setOnClickListener(cancel_button_click_listener); } catch (Exception e) { e.printStackTrace(); } }
Just change
pw = new PopupWindow(layout, 300, 470, true);
to like this
pw = new PopupWindow(layout, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
and if you need margins on any side do it in popup xml file. Also in xml use android:layout_height="wrap_content". Advantage of this is,- it will look same (if you put margin) in any device screen.