Android: Display custom dialog in center of the container

I added this to the dialog's custom style and it worked fine.

<item name="android:layout_gravity">center</item>

My dialog's width and height are set to wrap_content. The style's parent is

parent="@android:style/Theme.Light"


Change the fill_parent to wrap_content.I hope this will be the issue the dialog appear at the corner of the activity.It takes the space of whole layout.So changing this may help you to get what you realy wanted.

Window window = customdialog.getWindow();
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);

Use above code after dialog.show() statement