天天看点

根据父布局的宽高,动态设置控件的宽高

代码

//获取二维码父布局的宽度
        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);
            }
        });

        //获取二维码父布局的宽度
           

继续阅读