を表示されない私は、動的にテーブルの行を追加することに関する多くの記事を見てきましたが、私は私が欠けているのかわからないです。動的に追加されたテーブルの行が
私は次のことを実行すると、何も(脇アプリケーションのタイトルバーから)表示されません。
マイレイアウト:
<?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>
My活動:
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