xml에 TableLayout이 있으며 프로그래밍 방식으로 행을 추가하려고합니다.TableLayout에 동적으로 추가 된 뷰가 표시되지 않습니다.
LinearLayout deckBuilder = (LinearLayout) getLayoutInflater().inflate(R.layout.deckbuilder, null);
TableLayout deckGrid = new TableLayout(this.getApplicationContext());
int rows = getResources().getInteger(R.integer.deckbuilder_grid_rows);
int columns = getResources().getInteger(R.integer.deckbuilder_grid_columns);
deckGrid.setWeightSum(rows);
for (int i = 0; i < rows; ++i) {
TableRow row = new TableRow(this.getApplicationContext());
for (int j = 0; j < columns; ++j) {
ImageView iv = new ImageView(this.getApplicationContext());
row.addView(iv);
iv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1));
iv.setImageResource(R.drawable.my_image);
}
deckGrid.addView(row);
row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 1));
}
deckBuilder.addView(deckGrid);
deckGrid.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
문제는 내가 행에 추가 된 뷰 자체가 하나 표시되지 않는, 행을 표시되지 않는 것입니다 :
이
내 코드입니다.행 3 열 : 5. 여기에
가 deckbuilder에 대한 XML입니다은 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/deckbuilder_background"
android:orientation="vertical" >
</LinearLayout>
안녕하세요, 먼저 UI 구성 요소를 만들 때 applicationCOntext를 사용하면 안됩니다. 두 번째로 행과 열의 값을 출력 했습니까? 그렇다면 번호를 알려주세요. 우리에게 도움이 될 것입니다. 여기에 deckbuilder에 대한 xml을 추가하면 – Cata