这可能是一个非常简单的问题,但我没有找到任何解决方案。我的要求是这样的。给定图像的数量和行数,图像应该平均分布在行中。我正在这样做..但现在问题在于最坏的情况:例如。如果我给出的图像总数为 99,总行数为 50,那么在 49 行中,列应该是 2,每列一个图像,在第 50 列中,一列应该只有一个图像。我无法找到解决此问题的方法。请帮帮我。我在这里发布代码。请帮我。提前致谢。
@Override
protected void onPreExecute() {
HSC = new HorizontalScrollView(getApplicationContext());
VSC = new ScrollView(getApplicationContext());
tableLayout = new TableLayout(getApplicationContext());
tableLayout.setGravity(Gravity.CENTER);
}
@Override
protected Void doInBackground(Void... params) {
runOnUiThread(new Runnable() {
public void run() {
int a =0;
for (Integer row = 0; row < rows; row++) { //Rows are being plotted.
tableRow = new TableRow(getApplicationContext());
for (Integer col = 0; col < img; col++) {
/*Images shared into number of columns. Column=img/rows*/
image = new ImageView(getApplicationContext());
android.view.animation.Animation anim = animate(a);
/*android.view.animation.Animation anim = AnimationUtils
.loadAnimation(getApplicationContext(), R.anim.fadein);*/
image.startAnimation(anim);
image.setPadding(20, 20, 20, 20);
image.setImageResource(R.drawable.images);
tableRow.addView(image);
a++;
}
tableLayout.addView(tableRow);
}
VSC.addView(tableLayout);
HSC.addView(VSC);
setContentView(HSC);
}
});
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}