0

LinearLayoutプログラムで幅が等しい 2つを作成しようとしています:ここに画像の説明を入力

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 です)。どうすればそれができますか?

4

2 に答える 2

5
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.
于 2016-02-18T10:07:49.567 に答える
1

これを試して、

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            0,
            LinearLayout.LayoutParams.MATCH_PARENT,1.0
            );

weightsumが 2の場合は 1.0、それ以外の場合は 0.5

于 2016-02-18T10:03:58.863 に答える