我正在開發一個android應用程序。我需要顯示textview在右側的tablerow,下面是我使用的代碼,這個代碼有什麼錯?如何在androidrow中顯示textview到右側的表格
ScrollView src;
src=(ScrollView)findViewById(R.id.scrollView1);
TableLayout t1=new TableLayout(context);
TableRow.LayoutParams tableRowParams=new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT);
tableRowParams.gravity=Gravity.RIGHT | Gravity.CENTER_VERTICAL;
for(int i=0;i<count;i++)
{
TableRow tr=new TableRow(context);
TextView txt_peron_name=new TextView(context);
txt_peron_name.setTextColor(Color.BLACK);
txt_peron_name.setTextSize(15);
txt_peron_name.setText("Hello");
//txt_peron_name.setLayoutParams(tableRowParams);
tr.setBackgroundResource(R.drawable.cc1);
//tr.setLayoutParams(tableRowParams);
tr.addView(txt_peron_name);
t1.addView(tr,tableRowParams);
}// End of For Loop
src.removeAllViews();
src.addView(t1);
非常感謝@Chintan Rathod。它工作得很好。 –