I have two relative layouts that are currently displayed one below the other. I want the second layout to be displayed to right of the first relative layout programatically.
following is the code i used.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello2" />
</RelativeLayout>
</LinearLayout>
myAct.java
public class myAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layoutContainer = new LinearLayout(this);
layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// Arguments here: width, height, weight
LinearLayout.LayoutParams childLp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
RelativeLayout layoutLeft = new RelativeLayout(this);
layoutContainer.addView(layoutLeft, childLp);
RelativeLayout layoutRight = new RelativeLayout(this);
layoutContainer.addView(layoutRight, childLp);
}
}
Thanks in advance