我在寻找设置相对布局子视图参数所需的确切语法。我有一个根相对布局,我想将2个子文本视图并排放置,如下所示:
---------- --------- | Second | | First | ---------- ---------
所以我有:
public class RL extends RelativeLayout{
public RL(context){
TextView first = new TextView(this);
TextView second = new TextView(this);
first.setText('First');
first.setId(1);
second.setText('Second');
second.setId(2);
addView(first, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
LayoutParams.ALLIGN_PARENT_RIGHT ???);
addView(first, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
LayoutParams.ALLIGN_RIGHT_OF(first.getId()) ???);
}
}
如何设置相对对齐方式?
align_parent_right
,然后第二个是align_left_of first.id()
。 - Falmarri