How To Center Layout Inside Of Android Dialog?
I am trying to create a custom Dialog, and have its content centered, but it is always ending up left-aligned. Here is aboutdialog.xml:
Solution 1:
try to edit to this: a:layout_gravity="center_horizontal|center_vertical"
OR
use Relative_Layout and align linear layout to center of parent with fill_parent
for Relative wrap_content
for Linear.
although it is worked with me on center
Solution 2:
Modify Dialog's ViewGroup (FrameLayout) which holds your content layout. I use static method and invoke it inside onActivityCreated() in DialogFragments:
/**
* Center dialog content inside available space
* @param dialog
*/publicstaticvoidcenterDialogContent(Dialog dialog) {
ViewGroupdecorView= (ViewGroup) dialog.getWindow().getDecorView();
Viewcontent= decorView.getChildAt(0);
FrameLayout.LayoutParamscontentParams= (FrameLayout.LayoutParams)content.getLayoutParams();
contentParams.gravity = Gravity.CENTER;
content.setLayoutParams(contentParams);
}
Solution 3:
You're doing layout_gravity which is good, but since you do it to the outmost layout, it can't position itself relative to what's around it.
I think that wrapping the above layout inside another layout would do it
Solution 4:
Can you try changing your LinearLayout layout_gravity to just gravity? See the difference explained here: Gravity and layout_gravity on Android
Post a Comment for "How To Center Layout Inside Of Android Dialog?"