210_Dialog和AlertDialog各种情况调试
来源:互联网 发布:org.apache.http包 编辑:程序博客网 时间:2024/06/13 05:54
210_Dialog和AlertDialog各种情况调试
Dialog和AlertDialog有很多的不同
然后不同的情况下又会有很多的不同
比如先show还是先setContentView
有时候出来的情况就不一样
我就把调试的结果全部总结了然后比较一下
先是Dialog的先填充还是直接给R.layout,还有getWindow再设置setContentView和直接设置
public voidopen1(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
Dialog dialog = newDialog(context);
dialog.show();
dialog.getWindow().setContentView(inflate);
}
public voidopen2(View view) {
Dialog dialog = newDialog(context);
dialog.show();
dialog.setContentView(R.layout.dialog);
}
public voidopen3(View view) {
Dialog dialog = newDialog(context);
dialog.show();
dialog.getWindow().setContentView(R.layout.dialog);
}
public voidopen4(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
Dialog dialog = newDialog(context);
dialog.show();
dialog.setContentView(inflate);
}
这里的4种情况是一样的,也就是说是否先填充是一样的
getWindow这里虽然是一样的,但是AlertDialog就不一样了
这里要搞清楚对dialog设置setContentView和对window设置setContentView的区别
下面是AlertDialog的setContentView的不同情况
public void open3(View view) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.setContentView(R.layout.dialog);
}
public void open4(View view) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.getWindow().setContentView(R.layout.dialog);
}
两个显示很像,但是第二个比第一个窗口要小一点
所以对AlertDialog设置和对window设置是有区别的
然后我们看看想设置AlertDialog占满屏幕的不同情况
我们的布局很简单,width给的是match,height给的是wrap
public voidopen1(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
AlertDialog alertDialog =newAlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.setContentView(R.layout.dialog);
WindowManager.LayoutParams attributes = alertDialog.getWindow().getAttributes();
attributes.width= WindowManager.LayoutParams.MATCH_PARENT;
alertDialog.getWindow().setAttributes(attributes);
}
public voidopen2(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
AlertDialog alertDialog =newAlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.setContentView(inflate);
WindowManager.LayoutParams attributes = alertDialog.getWindow().getAttributes();
attributes.width= WindowManager.LayoutParams.MATCH_PARENT;
alertDialog.getWindow().setAttributes(attributes);
}
public voidopen3(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
AlertDialog alertDialog =newAlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.getWindow().setContentView(R.layout.dialog);
WindowManager.LayoutParams attributes = alertDialog.getWindow().getAttributes();
attributes.width= WindowManager.LayoutParams.MATCH_PARENT;
alertDialog.getWindow().setAttributes(attributes);
}
public voidopen4(View view) {
View inflate = View.inflate(context, R.layout.dialog,null);
AlertDialog alertDialog =newAlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.getWindow().setContentView(inflate);
WindowManager.LayoutParams attributes = alertDialog.getWindow().getAttributes();
attributes.width= WindowManager.LayoutParams.MATCH_PARENT;
alertDialog.getWindow().setAttributes(attributes);
}
我们发现,本来给window设置setContentView,会比直接对dialog设置小一点,也就是窄一点
但是现在4个都一样宽了,也就是说match这个属性对window起作用了
另外一点就是这说明了AlertDialog最宽就是这么宽,和屏幕就是会有一段距离
所以如果想充满屏幕得想其他办法,光给match是不够的.
然后我们试着不同的情况去占满屏幕
public voidopen2(View view) {
AlertDialog dialog =newAlertDialog.Builder(this).create();
dialog.show();
dialog.setContentView(R.layout.dialog);
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);
window.getDecorView().setPadding(0,0,0,0);
WindowManager.LayoutParams lp = window.getAttributes();
lp.width= WindowManager.LayoutParams.MATCH_PARENT;
lp.height= WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
public voidopen3(View view) {
AlertDialog dialog =newAlertDialog.Builder(this).create();
dialog.show();
dialog.setContentView(R.layout.dialog);
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);
WindowManager.LayoutParams lp = window.getAttributes();
lp.width= WindowManager.LayoutParams.MATCH_PARENT;
lp.height= WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
public voidopen4(View view) {
AlertDialog dialog =newAlertDialog.Builder(this).create();
dialog.show();
dialog.setContentView(R.layout.dialog);
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);
window.getDecorView().setPadding(0,0,0,0);
}
我们发现第一个成功了,
第二个上下左右都还是和屏幕有一段距离
第三个左右的间距还存在,上下没有间距了.
- 210_Dialog和AlertDialog各种情况调试
- AlertDialog和AlertDialog.Builder
- AlertDialog各种变化
- 关于各种alertDialog
- AlertDialog的各种用法
- android 各种对话框 AlertDialog
- 重访AlertDialog和AlertDialog.Builder
- [android]AlertDialog和AlertDialog.Builder
- AlertDialog提示对话框各种使用方法!
- 各种情况下MongoDB的启动和关闭
- js 判断窗口刷新和关闭,分各种情况
- Handler各种使用情况的内存泄露分析和避免
- 黑马程序员_Dialog对话框
- 自定义控件_dialog
- Android学习_Dialog
- 371_dialog透明背景
- AlertDialog和AlertDialog.Builder?两者区别
- AlertDialog和AlertDialog.builder(二)
- 输入一个年份判断是否是闰年
- 非对称加密、https加密和android apk证书签名
- flume1.6 avro测试
- Failed to read artifact descriptor--maven问题总结(能力工场)
- dump使用说明
- 210_Dialog和AlertDialog各种情况调试
- hbase自带的测试工具PerformanceEvaluation
- 自己的web服务器项目-实现多线程处理(三)
- 文本编辑器相关
- SMW0 HTML模版的形式上传文件 维护MIME类型
- 使用UIImagePickerController拍照和视频录制
- C/C++ 学习笔记:istringstream、ostringstream、stringstream 类介绍 和 stringstream类 clear函数的真正用途
- ajax
- Java 线程池并发编程详解