私の目標:
プログラムで追加された一連のビューを使用して、(xml で作成した見出しを使用して) テーブルにデータを入力しようとしています。計画は、いくつかTextViews
を aに追加し、それを作成した最終テーブルにTableRow
追加することです。このチュートリアルTableRow
に従おうとしました。
私の問題:
プログラムで追加されたビューは、xml で作成された TextViews が指示する列とインライン化されません。次のスクリーンショットをご覧ください。
私のコード: 1.) XML
<TableLayout
android:id="@+id/tableViewTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="@dimen/margin_EvalProblemTableRight"
android:layout_marginBottom="@dimen/margin_EvalProblemTableBottom"
android:text="@string/str_EvalProblemNumber"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="@dimen/margin_EvalProblemTableRight"
android:layout_marginBottom="@dimen/margin_EvalProblemTableBottom"
android:text="@string/str_EvalProblemString"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="@dimen/margin_EvalProblemTableRight"
android:layout_marginBottom="@dimen/margin_EvalProblemTableBottom"
android:text="@string/str_EvalProblemCorrectSolution"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="@dimen/margin_EvalProblemTableRight"
android:layout_marginBottom="@dimen/margin_EvalProblemTableBottom"
android:text="@string/str_EvalProblemUserSolution"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="@dimen/margin_EvalProblemTableRight"
android:layout_marginBottom="@dimen/margin_EvalProblemTableBottom"
android:text="@string/str_EvalProblemDuration"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
2.) ジャバ:
public class EvalActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eval);
TableLayout tableViewTable = (TableLayout) findViewById(R.id.tableViewTable);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button b = new Button(this);
b.setText("Button");
b.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView t1 = new TextView(this);
t1.setText("I am textView1");
t1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView t2 = new TextView(this);
t2.setText("I am textView2");
t2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView t3 = new TextView(this);
t3.setText("I am textView3");
t3.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView t4 = new TextView(this);
t4.setText("I am textView3");
t4.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tr.addView(b);
tr.addView(t1);
tr.addView(t2);
tr.addView(t3);
tr.addView(t4);
tableViewTable.addView(tr,(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)));
}
「ハードコードされた」xml-TableRow をプログラムで追加されたビューと行に結合するにはどうすればよいですか?