android自定義dialog記錄

自定義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,否則可能會顯示不全

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容