How to set the android property layout_alignParentBottom to a button dynamically

后端 未结 1 768
既然无缘
既然无缘 2020-12-30 07:01

I have a dynamic layout and I have a button. How can I set the property layout_alignParentBottom to that button so that it would appear in the bottom of my rela

相关标签:
1条回答
  • 2020-12-30 07:11

    This will only work if your layout is a RelativeLayout, as other ViewGroups don't understand 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);
    
    0 讨论(0)
提交回复
热议问题