Android如何在java代码中设置margin

Android如何在java代码中设置margin,也就是组件与组件之间的间距。

代码中设置:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
 params.setMargins(0, 5, 2, 0);


等同于


XML中设置:

<LinearLayout
		        android:
		        android:layout_width="fill_parent"
		        android:layout_height="fill_parent"
		        android:layout_marginRight="2dip"
		        android:layout_marginTop="5dip" >