以下方法为限制dialog的最小宽度以及最大高度,可以通过修改判断条件来控制最小或最大
/**
* 在dialog.show()前调用此方法
* @param mView dialog要显示的view
*/
private void setDialogSize(final View mView){
mView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
int oldRight, int oldBottom) {
int heightNow = v.getHeight();//dialog当前的高度
int widthNow = v.getWidth();//dialog当前的宽度
int needWidth = (int) (getWindowManager().getDefaultDisplay().getWidth() * 0.7);//最小宽度为屏幕的0.7倍
int needHeight = (int) (getWindowManager().getDefaultDisplay().getHeight() * 0.6);//最大高度为屏幕的0.6倍
if (widthNow < needWidth || heightNow > needHeight){
if (widthNow > needWidth){
needWidth = FrameLayout.LayoutParams.WRAP_CONTENT;
}
if (heightNow < needHeight){
needHeight = FrameLayout.LayoutParams.WRAP_CONTENT;
}
mView.setLayoutParams(new FrameLayout.LayoutParams(needWidth,
needHeight));
}
}
});
}