12

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 relative layout?

Or do you know another way?

Cristian
  • 198,401
  • 62
  • 356
  • 264
Nopcea Flavius
  • 303
  • 1
  • 3
  • 15

1 Answers1

57

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);
CorayThan
  • 17,174
  • 28
  • 113
  • 161
Kevin Read
  • 2,173
  • 16
  • 23