我将此TableRow的EditText插入到tablelayout中,此tablelayout插入到一个Scrollview中,此Scrollview插入到HorizontalScrollView中。 HorizontalScrollView还包含背景图像。问题是我无法正确滚动并显示所有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]);
}
答案 0 :(得分:1)
Gravity.CENTER
参数,或者滚动条将从其内容的中心滚动得足够大。它在那里,但你无法得到它。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
// ...
}