LayoutParams的addRule方法

自定义ViewGroup中,需要用LayoutParams对子View进行布局

1
2
3
mLeftParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
mLeftParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE);
mLeftParams.addRule(RelativeLayout.RIGHT_OF, R.id.leftView);

等价于

1
2
android:layout_alignParentLeft="true"
android:layout_toRightOf="@id/leftView"