나는 당신이 데이터베이스의 테이블이 아니라 TableLayout 뷰에 대해 이야기하고 있다고 가정한다. ??
그렇다면 여기에 3 열 3 행이있는 XML 예제가 있습니다.
각 < TableRow> 요소는 테이블에 행을 만들고 요소 안의 각 뷰는 "열"을 만듭니다. 나는 TextViews을 사용했지만, 그들은 등 ImageViews, 글고 될 수
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/RHE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="5dp">
<TableRow android:layout_height="wrap_content">
<TextView
android:id="@+id/runLabel"
android:text="R"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/hitLabel"
android:text="H"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/errorLabel"
android:text="E"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow android:layout_height="wrap_content">
<TextView
android:id="@+id/visitorRuns"
android:text="0"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/visitorHits"
android:text="0"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/visitorErrors"
android:text="0"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow android:layout_height="wrap_content">
<TextView
android:id="@+id/homeRuns"
android:text="0"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/homeHits"
android:text="0"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/homeErrors"
android:text="0"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
동적으로 코드에서이를 변경하려면이 같은 거라고 :
// reference the table layout
TableLayout tbl = (TableLayout)findViewById(R.id.RHE);
// delcare a new row
TableRow newRow = new TableRow(this);
// add views to the row
newRow.addView(new TextView(this)); // you would actually want to set properties on this before adding it
// add the row to the table layout
tbl.addView(newRow);
예, 내가 원하는을 테이블 레이아웃보기. 열의 위치가 잘못되었습니다. 기둥을 어떻게 배치합니까? 행을 어떻게 동적으로 추가 할 수 있습니까? – narayanpatra
'제대로 배치되지 않았다'는 말을 정확히 모르겠습니다. TableLayout는 내부의 항목과 마찬가지로 속성에 따라 크기가 조정됩니다. 아마 xml을 게시하고보고 싶은 내용이 있으면 질문에 대답 할 수있는 능력이 더 많을 것입니다. – Peter
나는 그대로 XML 파일의 코드를 사용했다. 처음 2 줄만 바꾸면됩니다. > xml version : "1.0"encoding = "utf- id/RHE " 많은 오류가 나타납니다. 내가 여기서 뭘하고있는거야? – narayanpatra