android中我们需要动态控制控件大小,可以设置控件的LayoutParams。
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);//设置left,top,right, bottom
imageView.setLayoutParams(layoutParams);