동적으로 테이블 행을 추가하는 것과 관련하여 많은 게시물을 보았습니다. 그러나 나는 무엇이 누락되었는지 잘 모릅니다.동적으로 추가 된 테이블 행이 표시되지 않습니다.
다음을 실행하면 아무 것도 표시되지 않습니다 (응용 프로그램 제목 표시 줄 제외).
내 레이아웃 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/table_view_test_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:id="@+id/tvt_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<RelativeLayout
android:id="@+id/tvt_scroll_relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/tvt_tableview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TableLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
내 활동 :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table_view);
TableLayout tableLayout = (TableLayout) findViewById(R.id.tvt_tableview);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView column1 = new TextView(this);
column1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
column1.setBackgroundColor(Color.YELLOW);
column1.setTextColor(Color.BLUE);
column1.setText("Col1 Value");
tableRow.addView(column1);
TextView column2 = new TextView(this);
column2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
column2.setBackgroundColor(Color.RED);
column2.setTextColor(Color.GREEN);
column2.setText("Col2 Value");
tableRow.addView(column2);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
//tl.refreshDrawableState();
//findViewById(R.id.tvt_scroll_relative).refreshDrawableState();
}
흥미 롭. 이것 모두는 나에게 좋게 보인다 (내가 여기의 무엇이라도 절대적으로 확실하지 않다. ..). 나는'TableLayout' 위의 다른 레이아웃에 다른'TextView'를 동적으로 추가하는 것을 권할 것입니다. * 표시 할 항목이 있는지 확인하십시오. 어떻게 작동되는지 알려주십시오. –
줄을 제거 tableRow.setLayoutParams(); 당신이 TableRow를 인스턴스화 한 후에, 나는 생각한다. 이 작품이 나에게 알려 주시면 솔루션으로 게시 할 수 있습니다. –
@Yashwanth Kumar, 혼자 그걸 제거하는 데 도움이되지 않았다. ViewGroup.LayoutParams를 TableRow.LayoutParams로 변경하거나 모두 제거하면 문제가 해결됩니다. – CrackerJack9