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