TableLayout을 사용하여 복잡한 격자를 만들려고합니다.다른 프로그램 내에서 TableRow를 추가 할 수 없습니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.15">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1">
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1">
</TableRow>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1">
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1">
</TableRow>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1"/>
</TableLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_red_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_red_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_light"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_light"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_red_light"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_red_light"
android:layout_weight="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_red_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_blue_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_green_light"
android:layout_weight="1"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_light"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.85"></LinearLayout>
문제가 있다는 것입니다 :이 코드에 의해
:이 같은 XML (그리드 상자의 일부가 강조되지 않음)에 의해 그것을 만들 관리 이 그리드의 파트 중 하나를 프로그램 적으로 만들려고하면 다른 TableRow의 자식 인 TableRow가 아니라 TableLayout의 직접 자식 인 TableRow 만 보여줍니다.
TableLayout table1 = new TableLayout(this);
//Add TableLayout to a FramLayout holding multiple TableLayouts
frame.addView(table1);
table1.setBackgroundResource(R.color.some_random_color_for_debugging);
for(int num = 0; num<2; num++){
//4x2
TableRow row = new TableRow(this);
TableLayout.LayoutParams par = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT, 1f);
row.setLayoutParams(par);
if(num==1){
row.setBackgroundResource(R.color.some_random_color_for_debugging1);
}
table1.addView(row, par);
for(int num1 = 0; num1<2; num1++){
//2x2
TableRow box = new TableRow(this);
TableRow.LayoutParams param = new TableRow.LayoutParams();
box.setLayoutParams(param);
if(num1==1){
box.setBackgroundResource(R.color.some_random_color_for_debugging2);
}
row.addView(box, par);
}
}
이 코드는 some_random_color_for_debugging의 배경색 절반 화면 some_random_color_for_debugging1을 만드는 :이 자바 코드를 사용합니다.
TableRow 행과 상자를 모두 표시하려면 어떻게해야합니까?
코드를 작성하려는 부분이 명확하지 않습니다. . 또한, 초기 레이아웃이 처음부터 나쁘다. 너무 많은 '무게'가 성능에 영향을 미치고 사용 중이다. – Luksprog
@Luksprog 무게를 사용하지 않고 이런 레이아웃을 만들 수 있다는 것을 알고 계십니까? 부모보기의 크기를 조절하는 것은 주어진 수의 상자로 나누기 전에 옵션입니다. – Magakahn