设置控件布局时:
LayoutParams leftTxtParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
方法一:addRule(int verb)
leftTxtParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
方法二:addRule(int verb, int anchor)
leftTxtParams.addRule(RelativeLayout.END_OF, img_left.getId());
此处第二个参数是控件ID,有关控件ID可以点击查看:
android在代码中为new出的控件设置ID及setId()异常