SoFunction
Updated on 2025-04-02

How to freely change the position of the Dialog window in Android

This article describes the method of android to freely change the position of the Dialog window. Share it for your reference. The details are as follows:

Dialog dialog = new Dialog(this);
(.dialog_layout);
("Custom Dialog");

 
//Get the current formWindow window = ();

//Reset lp = ();
window .setGravity( | );
 = 100; // New position X coordinate = 100; // New position Y coordinate = 300; // Width = 300; // high = 0.7f; // Transparency
// (lp);
//(This function will be called when the Window's Attributes changes)window .setAttributes(lp);
();

I hope this article will be helpful to everyone's Android programming design.