具体参照代码,有问题或者有更好的建议,欢迎提出。
package com.imeibi.mytools;import android.app.Dialog;import android.content.Context;import android.graphics.Point;import android.view.Display;import android.view.Gravity;import android.view.WindowManager;import com.imeibi.R;import com.imeibi.utils.CommonUtils;import java.util.List;/** * Created by mb on * 2015/3/4-13:36. * 自定义弹窗,没有按钮 */public class MyListDialog { private Context context; private ListlistStr; private Dialog myListDialog; /** * 列表弹窗 * * @param c * @param listStr */ public MyListDialog(Context c, List listStr) { this.context = c; this.listStr = listStr; myListDialog = new Dialog(c, R.style.MyDialog); myListDialog.setContentView(R.layout.list_dialog_layout); //设置显示 //正常显示listView,及操作...... } /** * 设置显示参数 */ public void setShow() { myListDialog.show(); //窗口管理器 WindowManager windowManager = myListDialog.getWindow().getWindowManager(); //获取默认显示窗口值 Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = myListDialog.getWindow().getAttributes(); Point outSize = new Point(); outSize.x = display.getWidth(); outSize.y = display.getHeight(); lp.width = outSize.x - CommonUtils.dip2px(context, 40); // 设置宽度 lp.height = outSize.y - CommonUtils.dip2px(context, 200);//设置弹窗的高度 lp.gravity = Gravity.CENTER;//弹窗居中显示 myListDialog.getWindow().setAttributes(lp); myListDialog.setCanceledOnTouchOutside(true); }}