Android以编程方式在relativelayout的底部设置linerlayout

Android以编程方式在relativelayout的底部设置linerlayout,android,Android,我想在relativelayout的底部添加一个linerlayout。我怎样才能做到这一点? 这是我正在使用的代码段: rl=new RelativeLayout(this); ll = new LinearLayout(this); buttons=new LinearLayout(this); buttons.setOrientation(LinearLayout.HORIZONTAL); ll.setOrientation(LinearLayout.VERTICAL); //butto

我想在relativelayout的底部添加一个linerlayout。我怎样才能做到这一点? 这是我正在使用的代码段:

rl=new RelativeLayout(this);
ll = new LinearLayout(this);
buttons=new LinearLayout(this);

buttons.setOrientation(LinearLayout.HORIZONTAL);
ll.setOrientation(LinearLayout.VERTICAL);
//buttons.addRule();

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT);
params.topMargin=450;
    //params.gravity = Gravity.BOTTOM;

rl.addView(ll);
rl.addView(buttons,params);

我认为这样做应该奏效:

rl=new RelativeLayout(this);
buttons=new LinearLayout(this);

buttons.setOrientation(LinearLayout.HORIZONTAL);

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

rl.addView(buttons, lp);

参考这个答案,它解释得很好