Skip to content

Instantly share code, notes, and snippets.

@marc0x71
Created April 30, 2016 06:00
Show Gist options
  • Save marc0x71/f571f4dfe328b662860cd4e80bd7f6af to your computer and use it in GitHub Desktop.
Save marc0x71/f571f4dfe328b662860cd4e80bd7f6af to your computer and use it in GitHub Desktop.
Set the width of the DialogFragment proportional to 90% of the screen width
@Override
public void onResume() {
// Set the width of the dialog proportional to 90% of the screen width
Window window = getDialog().getWindow();
Point size = new Point();
Display display = window.getWindowManager().getDefaultDisplay();
display.getSize(size);
window.setLayout((int) (size.x * 0.90), WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
super.onResume();
}
@samseen
Copy link

samseen commented Apr 9, 2023

Thank you!

@NguyenCongSon2402
Copy link

Good Idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment