For just two RelativeLayouts next to each other, you have the choice to archive. Horizontal LinearLayout would be the easiest in my opinion.
Edit: I never make layouts in code, but since you are probably reading a lot of XML documents, you should translate this example. Uses 50/50 space allocation for both layouts.
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" > </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" > </RelativeLayout> </LinearLayout>
Edit 2:
Definitely works, just tried this:
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.FILL_PARENT, 1); RelativeLayout layoutLeft = new RelativeLayout(this); layoutContainer.addView(layoutLeft, childLp); RelativeLayout layoutRight = new RelativeLayout(this); layoutContainer.addView(layoutRight, childLp);
user658042
source share