我正在尝试以编程方式创建两个宽度相等的LinearLayout
:
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
);
但我的所有线性布局都不可见(它们的宽度为0)。 我怎么能这样做?
答案 0 :(得分:4)
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.
答案 1 :(得分:1)
试试这个,
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0,
LinearLayout.LayoutParams.MATCH_PARENT,1.0
);
1.0如果 weightum 是2,则为其他0.5