I have tried to create a dialog that occupies the full screen width from the old AlertDialog builder to the new DialogFragment approach in the onCreateView() and onViewCreated() to get the displayed dialog to occupy the full width of the screen. I can certainly get the width and height values of the screen but regardless of how I try to force the dialog to use these values, they are ignored. The displayed dialog is always the same width regardless of orientation.
In my latest attempt I have an xml layout that I inflate. I need to use a custom view so I cannot define that view in xml. So I add it.
Here is the most current attempt I have in my DialogFragment code. Of course this is just one of many attempts I have made trying to follow hints from posts and Slidenerd videos.
public class PopupDialog extends DialogFragment implements View.OnClickListener
private static final String TAG = PopupDialog.class.getName();
Button cancel = null;
Button focus = null;
View viewInput = null;
public PopupDialog(View v, int id, int width, int height)
viewInput = v;
this.id = id;
this.width = width;
this.height = height;
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstance)
Log.d(TAG, "onCreateView of DialogFragment called.");
View viewDialog = inflator.inflate(R.layout.popup_dialog, null);
// RelativeLayout relativeLayout = (RelativeLayout)viewDialog;
// LayoutParams params = new LayoutParams(width, height);
// Point point = new Point();
// Activity activity = getActivity();
// if(point.x > point.y)
if(width > height)
ViewParent parent = viewInput.getParent();
if(parent != null)
Log.d(TAG, "View already present. Removing.");
LayoutParams params = new LayoutParams(width, height);
cancel = (Button)viewDialog.findViewById(R.id.btn_cancel);
focus = (Button)viewDialog.findViewById(R.id.btn_focus);
public void onViewCreated(View view, Bundle savedInstanceState)
Log.d(TAG, "onViewCreated of DialogFragment called.");
WindowManager.LayoutParams wmlp = getDialog().getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 10; //x position
wmlp.y = 450 * (id) + 10;
// wmlp.width = width;
// wmlp.height = height;
I am plotting a sine wave. The view has the correct size as the sine wave has a range of 0 to 12 but in the landscape orientation the displayed dialog box only gets a little more than half way, so 0 to 6 + is seen and then one has to wait for the wave to recycle as it plots from 6 to 12 before it becomes visible again when it goes back to 0. I AM able to place the dialog box upper left hand corner.
Does anyone know how to solve this problem? I went to the fragment because I was led to believe that the canned AlertDialog approach was fixed in width and there was nothing one could do. I am facing the same limitation with the DialogFragment.
try adding this code in on create() method after setContentView