如何想新建布局的话,可以这样写
LinearLayout.LayoutParamslp=newLinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left,top,right,bottom);
imageView.setLayoutParams(lp);
如何想使用原来本身的布局的话,可以使用如下的代码:
MarginLayoutParamsmarginParams=newMarginLayoutParams(image.getLayoutParams());
marginParams.setMargins(left_margin,top_margin,right_margin,bottom_margin);
LinearLayout.LayoutParamslayoutParams=new LinearLayout.LayoutParams(marginParams);
image.setLayoutParams(layoutParams);
参考文章:http://stackoverflow.com/questions/3416087/how-to-set-margin-of-imageview-using-code-not-xml