Q:

How to create two LinearLayout with equal width programmatically?

I'm trying to create two LinearLayout with equal width programmatically:

mGroupLayout.setOrientation(HORIZONTAL);
mGroupLayout.setWeightSum(2f);

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        0,
        LinearLayout.LayoutParams.WRAP_CONTENT
        );
params.weight = 1.0f;

leftLayout = new LinearLayout(getContext());
leftLayout.setOrientation(VERTICAL);
leftLayout.setLayoutParams(params);

mGroupLayout.addView(
        leftLayout,
        params
        );

rightLayout = new LinearLayout(getContext());
rightLayout.setOrientation(VERTICAL);
rightLayout.setLayoutParams(params);

mGroupLayout.addView(
        rightLayout,
        params
        );

But all my linear layouts isn't visible (they has 0 width).
How i can do that?

A:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        0,
        LinearLayout.LayoutParams.MATCH_PARENT,1
        );
FirstLinearLayout.setLayoutParams(params );
SecondLinearLayout.setLayoutParams(params );

1 is the Weight of each layout.

