我做了一个程序,我用表格布局作为我的布局,我想把滚动条放进去,我用了 table.setVerticalScrollBarEnabled(true); 但我没有工作,我最好的补救措施是什么?这是我的代码:
TableLayout table = new TableLayout(getApplicationContext());
table.setVerticalScrollBarEnabled(true);// i used this but it did not work
table.setPadding(10, 10, 10, 10);
TableRow tableRow = new TableRow (getApplicationContext());
TextView txt = new TextView (getApplicationContext());
TextView txt2 = new TextView (getApplicationContext());
TextView txt3 = new TextView (getApplicationContext());
TextView txt4 = new TextView (getApplicationContext());
TextView txt5 = new TextView (getApplicationContext());
TextView txt6 = new TextView (getApplicationContext());
tableRow.addView(txt);
tableRow.addView(txt2);
tableRow.addView(txt3);
tableRow.addView(txt4);
tableRow.addView(txt5);
tableRow.addView(txt6);
tableRow.setBackgroundColor(Color.GRAY);
txt.setText("Question ");
txt2.setText("Excellent ");
txt3.setText("Best ");
txt4.setText("Better ");
txt5.setText("Good ");
txt6.setText("Poor ");
txt.setTextColor(Color.BLACK);
txt2.setTextColor(Color.BLACK);
txt3.setTextColor(Color.BLACK);
txt4.setTextColor(Color.BLACK);
txt5.setTextColor(Color.BLACK);
txt6.setTextColor(Color.BLACK);
table.addView(tableRow);
int j=0;
for(j = 1; j<=count; j++){
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
tableRow = new TableRow (getApplicationContext());
TextView name = new TextView (getApplicationContext());
EditText et2 = new EditText (getApplicationContext());
EditText et3 = new EditText (getApplicationContext());
EditText et4 = new EditText (getApplicationContext());
EditText et5 = new EditText (getApplicationContext());
EditText et6 = new EditText (getApplicationContext());
et2.setBackgroundColor(color);
et3.setBackgroundColor(color);
et4.setBackgroundColor(color);
et5.setBackgroundColor(color);
et6.setBackgroundColor(color);
name.setText("Q#"+Integer.toString(j));
tableRow.addView(name);
tableRow.addView(et2);
tableRow.addView(et3);
tableRow.addView(et4);
tableRow.addView(et5);
tableRow.addView(et6);
table.addView(tableRow);
}
TableRow tableRow1 = new TableRow (getApplicationContext());
Button showtable = new Button(getApplicationContext());
tableRow1.addView(showtable);
showtable.setText("Show Table");
showtable.setTextSize(8);
table.addView(tableRow1);
setContentView(table);