I am trying to add some buttons to a Relative Layout programatically. I used some examples seen on StackOverflow, but for some reason I cannot understand, my code is not working: I want to have my buttons one above the other, but they end up being one on top of the other. Here is my layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.android.myApp.MainActivity" >
</RelativeLayout>
And here is my code:
mLayout = (RelativeLayout) findViewById(R.id.mainLayout);
RelativeLayout.LayoutParams lprams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
Button btnTag = new Button(this);
btnTag.setText("Button0");
btnTag.setId(0);
btnTag.setOnClickListener(mGlobalOnCLickListener);
mLayout.addView(btnTag, lprams);
lprams.addRule(RelativeLayout.BELOW, 0);
btnTag = new Button(this);
btnTag.setText("Button2");
btnTag.setId(1);
btnTag.setOnClickListener(mGlobalOnCLickListener);
mLayout.addView(btnTag, lprams);
lprams.addRule(RelativeLayout.BELOW, 0);