2

我将 EditText 的 TableRow 插入到 tablelayout 中,这个 tablelayout 插入到一个 Scrollview 中,这个 Scrollview 插入到一个 Horizo​​ntalScrollView 中。Horizo​​ntalScrollView 还包含背景图像。问题是我无法正确滚动并显示所有 EditText。你能帮助我吗?

FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
HorizontalScrollView HSC = new HorizontalScrollView(this); 
HSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
HSC.setBackgroundResource(R.drawable.lavagna);
ScrollView VSC = new ScrollView(this);
VSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TableLayout tableLayout = new TableLayout(this);
tableLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
values = new EditText[r][c];
for (int i = 0; i < r; i++){           
tableRow = new TableRow(this); 
tableRow.setGravity(Gravity.CENTER);
for (int j = 0; j < c; j++){
values[i][j] = new EditText(this);
values[i][j].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL);
values[i][j].setHint("r: " + (i) + " " + "c: " + (j));
values[i][j].setPadding(10, 10, 10, 10);
tableRow.addView(values[i][j]);
}           
4

1 回答 1

1
  1. 删除Gravity.CENTER参数,否则滚动条将从其内容的中心滚动到足够大的位置。它在那里,但你无法得到它。
  2. 纠正各种values

代码:

FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
HorizontalScrollView HSC = new HorizontalScrollView(this);
HSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
HSC.setBackgroundResource(R.drawable.lavagna);        
ScrollView VSC = new ScrollView(this);
VSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,             LayoutParams.WRAP_CONTENT));
TableLayout tableLayout = new TableLayout(this);
tableLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,     LayoutParams.WRAP_CONTENT));  
// you may or may not change here and below 
// values = new EditText[15][15];
for (int i = 0; i < 15; i++){           
    TableRow tableRow = new TableRow(this); 
    tableRow.setGravity(Gravity.CENTER);
    for (int j = 0; j < 15; j++){
        EditText value = new EditText(this);
        value.setInputType(InputType.TYPE_CLASS_NUMBER |     InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        value.setHint("r: " + (i) + " " + "c: " + (j));
        value.setPadding(10, 10, 10, 10);
        tableRow.addView(value);
    }
    tableLayout.addView(tableRow);
}
VSC.addView(tableLayout);
HSC.addView(VSC);
frameLayout.addView(HSC);
// ... add frameLayout
// ...
}
于 2012-04-26T13:04:55.997 回答