警报对话框显示非常缓慢

时间:2014-06-11 10:56:22

标签: android android-layout android-dialog

我正在使用“警报对话框”来显示自定义视图,但警报对话框的速度非常慢。大约需要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>

2 个答案:

答案 0 :(得分:0)

试用此代码:

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

答案 1 :(得分:0)

// Try this way,hope this will help you to solve your problem.

dialog.xml
<CalendarView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height ="match_parent"/>

Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.dialog);
dialog.show();
相关问题