天天看點

根據父布局的寬高,動态設定控件的寬高

代碼

//擷取二維碼父布局的寬度
        final ViewTreeObserver vto = rlDialog.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                rlDialog.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                codeWidth = rlDialog.getWidth();
                Log.i("123", "寬is: "+codeWidth);
                RelativeLayout.LayoutParams paramsCode = new RelativeLayout.LayoutParams(codeWidth,codeWidth);
                ivQcodeDialog.setLayoutParams(paramsCode);
            }
        });

        //擷取二維碼父布局的寬度
           

繼續閱讀