WindowManager winManage = getWindowManager() ;Display winDisplay = winManage.getDefaultDisplay() ;int winHeight = winDisplay.getHeight() ;int winWeight = winDisplay.getWidth() ;

获取屏幕的长度和宽度,这个在Dialog中同样适用的

// 自定义对话框

class IdentikitDialogs extends Dialog implements android.view.View.OnClickListener {private Button b1;private Window window = null;private TextView tvMsg ;private String msg ;public IdentikitDialogs(Context context, String msg) {super(context);this.msg = msg ;}public void setDisplay() {setContentView(R.layout.identikit_dialog);// 设置对话框的布局tvMsg = (TextView)this.findViewById(R.id.tv_identikit_action) ;tvMsg.setGravity(Gravity.CENTER) ;tvMsg.setText(msg) ;b1 = (Button) findViewById(R.id.clo);b1.setOnClickListener(this);setProperty();//setTitle("自定义对话框");// 设定对话框的标题show();// 显示对话框}// 要显示这个对话框,只要创建该类对象.然后调用该函数即可.public void setProperty() {WindowManager winManage = getWindowManager() ;Display winDisplay = winManage.getDefaultDisplay() ;int winHeight = winDisplay.getHeight() ;int winWeight = winDisplay.getWidth() ;window = getWindow();//    得到对话框的窗口.WindowManager.LayoutParams wl = window.getAttributes();wl.x = 0;// 这两句设置了对话框的位置.0为中间wl.y = 180;wl.alpha = 0.6f;// 这句设置了对话框的透明度//wl.gravity = Gravity.BOTTOM;wl.height = winHeight ;wl.width = winWeight ;wl.gravity = Gravity.TOP ;window.setAttributes(wl);}@Overridepublic void onClick(View v) {dismiss();// 取消}} //end class

其中setContentView(R.layout.identikit_dialog);// 设置对话框的布局

是自己在xml文件中定义的布局

更多相关文章

  1. Android(安卓)设置圆角按下改变颜色按钮
  2. Android(安卓)ImageView显示网络图片
  3. ffmpeg支持android硬件解码mediacodec
  4. android 横竖屏等设置
  5. android 常用代码
  6. android设置图片变化的四种效果代码
  7. MSDK接入 中的各种问题
  8. Android(安卓)ExpandableListView显示模板
  9. Android(安卓)音量 获取 设置

随机推荐

  1. 如何测试返回的json结果?
  2. 【php】php开发的前期准备
  3. PHP连接mysql模板
  4. thinkphp5 数据库和模型详解 之1 数据库
  5. jQuery PHP:检查用户名是否已经存在
  6. php 项目bug 快速定位
  7. php随机生成验证图片
  8. PHP正则表达式的高级技巧
  9. 从php中的单行获取数据[重复]
  10. 如何在php中找到更轻或更暗版本的十六进