目前项目需要在前端显示小窗口,里面包含内容比较多,有图片、按钮、文字、编辑框都可以按照一个xml格式写成layout布局了不知道自定义对话框可否显示出来如果不能,那别的思路该是什么呢?请教

解决方案 »

  1.   

    可以啊!你先写个布局文件比如xx.xml;这个布局文件中包含你要显示的那些内容;然后通过一下代码来获取你的布局文件:
    LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
    View view=inflater.inflate(R.layout.inflater, null);
    得到你的布局文件之后,你就可以引用你布局文件中的内容,比如:
    ImageButton imageButton=(ImageButton)view.findViewById(R.id.imageButton);
    取得这些控件对象之后,就可以设置它们的值了。
    设置好之后,再把view添加到对话框中。使用addView(view);方法即可!
    不懂的话,可以去看下这个http://blog.csdn.net/android_tutor/article/details/5513869
      

  2.   

    可以啊,比如一个例子
    servicelistxml<?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         android:layout_width="fill_parent" android:layout_height="fill_parent" 
         android:orientation="horizontal">  
         <LinearLayout android:layout_width="fill_parent" 
             android:layout_height="wrap_content" android:orientation="horizontal">  
             <TextView android:layout_width="wrap_content" 
                 android:layout_height="wrap_content" android:text="Name:" />  
             <EditText android:layout_width="fill_parent" 
                 android:layout_height="wrap_content" android:id="@+id/editName"></EditText>  
         </LinearLayout>  
         <LinearLayout android:layout_width="fill_parent" 
             android:layout_height="wrap_content" android:orientation="horizontal">  
             <TextView android:layout_width="wrap_content" 
                 android:layout_height="wrap_content" android:text="Age:"></TextView>  
             <EditText android:layout_width="fill_parent" 
                 android:layout_height="wrap_content" android:id="@+id/editAge" android:inputType="number"></EditText>  
         </LinearLayout>  
    </LinearLayout> 
    程序中使用,mainmap为ActivityLayoutInflater layoutInflater = LayoutInflater.from(mainmap);  
     View AddEmployee = layoutInflater.inflate(R.layout.servicelist, null);     
     new AlertDialog.Builder(mainmap).setTitle("更改地图").setView(  
     AddEmployee).setPositiveButton("应用",  
            new DialogInterface.OnClickListener() {  
                @Override 
                public void onClick(DialogInterface dialog, int which) {  
                    //insertEmployee();  
                }  
            }).setNegativeButton("取消",  
            new DialogInterface.OnClickListener() {  
                @Override 
                public void onClick(DialogInterface dialog, int which) {                     
                }  
            }).show(); 
      

  3.   

    http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html这里里面最后一种就是你要的形式。
      

  4.   

    谢谢各位,有思路了还有一个小问题,因为项目需要很多种对话框,我打算用onCreateDialog都创建出来怎么自定义对话框大小呢网上的代码
    WindowManager m = getWindowManager(); 
    Display d = m.getDefaultDisplay(); //为获取屏幕宽、高 WindowManager.LayoutParams p = getWindow().getAttributes(); 
    //获取对话框当前的参数值 
    p.x = 0; //设置位置 默认为居中
    p.y = 0; //设置位置 默认为居中
    p.height = (int) (d.getHeight() * 0.5); //高度设置为屏幕的0.6 
    p.width = (int) (d.getWidth() * 0.5); //宽度设置为屏幕的0.95 
    this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) p);一下子把Activity都变小了
      

  5.   

    view.setMinimumHeight(***);
    v.setMinimumWidth(***);已经实现了,嘿嘿