Android中如何在代码中设置View的宽和高?


Android中如何在代码中设置View的宽和高?

https://zhidao.baidu.com/question/536302117.html


动态设置RecyclerView的高度


android 动态设置控件的高度,使用对应布局中的dp值


LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) myView.getLayoutParams();

linearParams.height=((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 42, getResources().getDisplayMetrics()));

myView.setLayoutParams(linearParams);

the width, either MATCH_PARENT, WRAP_CONTENT or a fixed size in pixels

https://stackoverflow.com/questions/17383285/what-unit-of-measure-does-layoutparams-use