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

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

问题描述

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

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.希望这是activity一角出现对话框的问题,占用了整个布局的空间.所以改了这可能会帮助您获得真正想要的东西.

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

在 dialog.show() 语句后使用上面的代码

Use above code after dialog.show() statement

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

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