私は2日間、ネストされた線形レイアウト(線形レイアウト内の線形レイアウト)を作成しようとしましたが、ほとんど成功しませんでした。私のマスターレイアウトには、45、45、10の重みが付けられた3つのセクションがあります。これを実行すると、うまく機能しているように見えます。画面に異なる色の長方形が3つ表示されます。
「サブ」線形レイアウトを作成してマスターに追加すると、サブレイアウトが画面を支配します。劣線形レイアウトの重みは35、35、30です。したがって、画面上で上部の長方形が3つの薄い長方形に分割されているのがわかります。代わりに、サブレイアウトに属する3つの長方形を取得します。
何か案は?
public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);
// Ensure there is a full screen blank window to work with
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
testViewA = new TestView(this);
testViewB = new TestView(this);
testViewC = new TestView(this);
testViewD = new TestView(this);
testViewE = new TestView(this);
testViewF = new TestView(this);
testViewA.color = 0;
testViewB.color = 1;
testViewC.color = 2;
testViewD.color = 3;
testViewE.color = 4;
testViewF.color = 5;
LinearLayout.LayoutParams paramsA = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .45f);
LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .45f);
LinearLayout.LayoutParams paramsC = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .10f);
LinearLayout.LayoutParams paramsX = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .35f);
LinearLayout.LayoutParams paramsY = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .35f);
LinearLayout.LayoutParams paramsZ = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, .30f);
paramsA.setMargins(10, 10, 10, 10);
paramsB.setMargins(10, 10, 10, 10);
testViewA.setLayoutParams(paramsA);
testViewB.setLayoutParams(paramsB);
testViewC.setLayoutParams(paramsC);
testViewD.setLayoutParams(paramsX);
testViewE.setLayoutParams(paramsY);
testViewF.setLayoutParams(paramsZ);
LinearLayout sub1 = new LinearLayout(this);
sub1.setOrientation(LinearLayout.VERTICAL);
sub1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
sub1.addView(testViewD);
sub1.addView(testViewE);
sub1.addView(testViewF);
LinearLayout masterL = new LinearLayout(this);
masterL.setOrientation(LinearLayout.VERTICAL);
masterL.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
masterL.addView(sub1);
masterL.addView(testViewB);
masterL.addView(testViewC);
setContentView(masterL);
}