gpt4 book ai didi

Android:在容器中心显示自定义对话框

转载 作者:IT老高 更新时间:2023-10-28 23:17:15 27 4
gpt4 key购买 nike

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

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的边框。一旦我使用了这条线,对话框就会出现在平板电脑的左上角?

谁能帮我解决这个问题?

最佳答案

将 fill_parent 更改为 wrap_content。我希望这将是对话框出现在 Activity 角落的问题。它占用了整个布局的空间。因此更改它可能会帮助您获得真正想要的内容。

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

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

关于Android:在容器中心显示自定义对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10412192/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com