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

时间:2013-11-10 11:30:20

标签: android

我想在relativelayout的底部添加一个linearlayout。我怎么能实现这一目标? 这是我正在使用的代码段:

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);

1 个答案:

答案 0 :(得分:0)

我认为这样的事情应该有效:

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);