安卓:在容器中心显示自定义对话框 [英] Android: Display custom dialog in center of the container

查看:114
本文介绍了安卓:在容器中心显示自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示自定义对话框作为容器的中心?

How to display custom dialog as a center of the container?

Dialog customdialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar); 
Window window = customdialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
window.setGravity(Gravity.CENTER);

R.style.Theme_Translucent_NoTitleBar - 用来除去边框cutomdialog。有一次,我用这条线的对话框将出现在平板电脑的左上边角?

R.style.Theme_Translucent_NoTitleBar - is used to remove border for cutomdialog. Once i used this line the dialog will appear at the topleft corner of the tablet?

谁能帮我解决这个问题呢?

Can anyone help me to solve this issue?

推荐答案

更​​改FILL_PARENT到wrap_content.I希望这将是在对话框出现在activity.It角落的问题,需要整个layout.So的改变空间这可以帮助你得到你真的想要的。

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);

这篇关于安卓:在容器中心显示自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆