2013-03-23 64 views
0

我正在制作一个自定义alertdialog有一个图像。我面临的问题如下:Android AlertDialog问题与ImageView

1)对于屏幕较小的设备,此警报对话框看起来太大。 aletdialog按钮不在屏幕上(正面和负面的按钮)。

2)alertdialog正在绘制两次。即有两个alertdialogs一个在另一个上,我必须点击正面按钮两次才能关闭它们。

这里是alertdialog代码: -

AlertDialog.Builder alertdialog = new AlertDialog.Builder(
        Activity.this); 
      alertdialog.setTitle("Title "); 
      alertdialog.setMessage("The MEssage "); 


      LayoutInflater layoutinf= LayoutInflater.from(Activity.this); 
      final View view = layoutinf.inflate(R.layout.layoutfile, null); 
      alertdialog.setView(view); 
      alertdialog.setPositiveButton("Button1", 
        new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, 
           int which) { 
          //do something 
         } 
        }); 
    alertdialog.show(); 

任何指针将会很有帮助。

感谢

+0

详细信息您提供的是不利于我们找出问题 – Pragnani 2013-03-23 17:30:32

+0

嗨Pragnani, 问题1中,alertdialog箱正面和负面的按钮超出了小屏幕设备的屏幕。是否有任何属性可以设置,以确保完整的alertdialog(包括图像和按钮)完全不会被裁剪。 – learner 2013-03-23 18:01:58

+0

不要在xml中设置视图及其子项的固定高度和宽度。 – Pragnani 2013-03-23 18:11:16

回答

1

对于第二个问题的警告对话框应该是这样的:

AlertDialog.Builder alertdialog= new AlertDialog.Builder(this); 
alertdialog.setTitle("Title"); 
alertdialog.setPositiveButton("OK", okListener); 
alertdialog.setNegativeButton("Cancel", cancelListener); 
AlertDialog alertdialogDlg = alertdialog.create(); 
alertdialogDlg.show(); 

public DialogInterface.OnClickListener okListener = new  
DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface dialog, int which) { 
      //do something 
     } 
    };