下面是重写dialog的代码,想请问一下如何修改对话框的大小,自适应屏幕的那种
publicclassDialog_SerialPortextendsDialog{privateSparseArray<View>mViews;privateViewm...
public class Dialog_SerialPort extends Dialog {
private SparseArray<View> mViews;
private View mConverView;
public Dialog_SerialPort(Context context, int layout, int style) {
this(context, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT, layout, style);
}
public Dialog_SerialPort(Context context, int width, int height,
int layout, int style) {
super(context, style);
// set content
mViews = new SparseArray<View>();
this.mConverView = LayoutInflater.from(context).inflate(layout, null,
false);
// 记住这一步
mConverView.setTag(this);
setContentView(layout);
Window window = getWindow();
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = window.getAttributes();
//lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
}
例如:对话框宽高是屏幕的0.5这样的 展开
private SparseArray<View> mViews;
private View mConverView;
public Dialog_SerialPort(Context context, int layout, int style) {
this(context, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT, layout, style);
}
public Dialog_SerialPort(Context context, int width, int height,
int layout, int style) {
super(context, style);
// set content
mViews = new SparseArray<View>();
this.mConverView = LayoutInflater.from(context).inflate(layout, null,
false);
// 记住这一步
mConverView.setTag(this);
setContentView(layout);
Window window = getWindow();
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = window.getAttributes();
//lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
}
例如:对话框宽高是屏幕的0.5这样的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询