Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the android property layout_alignParentBottom to a button dynamically

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?

like image 631
Nopcea Flavius Avatar asked Feb 06 '11 16:02

Nopcea Flavius


1 Answers

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);
like image 64
Kevin Read Avatar answered Jan 01 '23 09:01

Kevin Read