- // ConstraintLayout.LayoutParams linearParams =(ConstraintLayout.LayoutParams) imDanci.getLayoutParams();
- //// 2. 设置布局的高度 后面的参数就是对应 xml 中的 42dp 可以根据需要进行改变
- // linearParams.height=((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ConstraintLayout.LayoutParams.WRAP_CONTENT, getResources().getDisplayMetrics()));
- //// 3. 最后设置下控件的布局就可以了
- // imDanci.setLayoutParams(linearParams);
- // RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- // lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
- //// lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
- // lp.height=(int)(bgHeight/5.5987558);
- // inflate.setLayoutParams(lp);
来源: http://www.bubuko.com/infodetail-3653615.html