ConstraintLayout布局中,设置 setLayoutParams时,约束失效

在ConstraintLayout布局中,设置 setLayoutParams时,约束失效。
解决办法:

                int newWidth = progress+minWidth;
                int newHeight = ((int) (newWidth * 3 / 4));
                //解决办法就是先得到原来的params然后,再设置回去。
                ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(((ConstraintLayout.LayoutParams) imageView.getLayoutParams()));
                layoutParams.width=newWidth;
                layoutParams.height = newHeight;
                imageView.setLayoutParams(layoutParams);
                text1.setText("图像宽度:"+newWidth+"--高度:"+newHeight);

你可能感兴趣的:(ConstraintLayout布局中,设置 setLayoutParams时,约束失效)