代碼
//擷取二維碼父布局的寬度
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);
}
});
//擷取二維碼父布局的寬度