自定義dialog時兩個問題記錄一下
一.自定義的dialog里面有列表的時候,并且要限制最大寬高
此時處理兩點:
1.添加一下代碼至自定義的dialog中,動態(tài)計算寬高
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus) {
return;
}
setHeight();
}
/**
* 設(shè)置彈框的大小
*/
private void setHeight() {
Window window = getWindow();
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
WindowManager.LayoutParams attributes = window.getAttributes();
if (window.getDecorView().getHeight() >= (int) (displayMetrics.heightPixels * 0.8)) {
attributes.height = (int) (displayMetrics.heightPixels * 0.8);
}
if (window.getDecorView().getWidth() >= (int) (displayMetrics.widthPixels * 0.8)) {
attributes.width = (int) (displayMetrics.widthPixels * 0.8);
}
window.setAttributes(attributes);
}
2.給dialog布局中的recycleView設(shè)置權(quán)重
二.dialog布局中的textView寬要設(shè)置成match_parent,否則可能會顯示不全