Reputation: 3442
< RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
< Button android:text="Previous"
android:layout_height="wrap_content"
android:id="@+id/MeasurePrev"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content">
< / Button>
< / RelativeLayout >
Can anyone tell me how can i do this using Java code or in activity class? I do not know how to set android:layout_alignParentBottom="true". I want to implement whole view via java code.
Upvotes: 5
Views: 12765
Reputation: 50442
Here is a dynamic equivalent of your code :
RelativeLayout rl = new RelativeLayout(this);
LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rl.setLayoutParams(params);
Button button = new Button(this);
button.setText("Previous");
LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
button.setLayoutParams(params1);
rl.addView(button);
Upvotes: 16