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