gpt4 book ai didi

android - 自定义警报对话框在 Android 上未垂直居中

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:44:01 27 4
gpt4 key购买 nike

我制作了一个在游戏结束时显示的自定义警告对话框,以便玩家可以输入其名称来保存它。问题是当我在出现的对话框上调用 show() 但它不是垂直居中!无论我在 xml 中设置什么属性或使用 setGravity() 时,它都比应有的要低一些。

我认为这与 the one mentioned here 是同一个问题, 但没有人给出正确的答案。

感谢您的帮助。

有关详细信息,这是我的代码:

    AlertDialog.Builder builder;

LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.newrecord,(ViewGroup)findViewById(R.layout.shoot));

builder = new AlertDialog.Builder(this);
builder.setView(layout);

newRecDialog = builder.create();

下面是 newrecord.xml 的 XML 布局的第一个元素的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
android:padding="10dp"
android:baselineAligned="true">

这是输出截图: alt text
(来源:free.fr)

最佳答案

错误描述here . AlertDialog 为标题/图标面板保留空间,即使既没有标题也没有图标。

我认为修复非常简单:它应该将顶部面板布局设置为 GONE,就像在没有按钮的情况下对按钮面板所做的那样。在此之前,唯一的解决方法是实现您自己的 Dialog 子类。

关于android - 自定义警报对话框在 Android 上未垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3280944/

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