1、定义LayoutParams
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//定义一个LayoutParams
2、在LayoutParams中设置marginLeft
layoutParams.setMargins(20,0,0,0);//4个参数按顺序分别是左上右下
3、把这个LayoutParams设置给控件
mView.setLayoutParams(layoutParams); //mView是控件
照一下思路:
LinearLayout.LayoutParams abc = new LinearLayout.LayoutParams(。。。。。);
abc.setMargins(。。。。);
imageView.setLayoutParams(abc);