如何将android属性布局\u alignParentBottom动态设置为按钮

如何将android属性布局\u alignParentBottom动态设置为按钮,android,dynamic,button,Android,Dynamic,Button,我有一个动态布局和一个按钮。如何将属性layout\u alignParentBottom设置为该按钮,使其显示在相对布局的底部 或者您知道另一种方法吗?只有当您的布局是相对布局时,此方法才会起作用,因为其他视图组不了解对齐方式 RelativeLayout layout = findViewById(R.id.my_relative_layout); Button button = new Button(this); // your button lp = new RelativeLayout

我有一个动态布局和一个按钮。如何将属性
layout\u alignParentBottom
设置为该按钮,使其显示在相对布局的底部


或者您知道另一种方法吗?

只有当您的布局是相对布局时,此方法才会起作用,因为其他视图组不了解对齐方式

RelativeLayout layout = findViewById(R.id.my_relative_layout);
Button button = new Button(this); // your button
lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // You might want to tweak these to WRAP_CONTENT
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(button, lp);

不客气。别忘了接受一个有效的答案。