gpt4 book ai didi

android - 警报对话框显示非常缓慢

转载 作者:太空狗 更新时间:2023-10-29 15:03:37 27 4
gpt4 key购买 nike

我正在使用警报对话框来显示自定义 View ,但是警报对话框出现得非常慢。显示大约需要 10 或 15 秒。这是我的代码有什么问题。

LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vDialog = layoutInflater.inflate(R.layout.dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(vDialog);
AlertDialog ad = builder.create();
ad.show();

这是我的 dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height ="match_parent" >

<CalendarView
android:layout_width="50dp"
android:layout_height ="50dp">
</CalendarView>

</FrameLayout>

最佳答案

试试这段代码:

final Dialog dialog = new Dialog(context,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.CENTER;

dialog.getWindow().setAttributes(lp);

dialog.show();

关于android - 警报对话框显示非常缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24161163/

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