我試圖在運行時通過代碼在表格佈局中創建我的遊戲(一個圖像是一個遊戲點),並且一切正常,但只在onTouch事件中,它非常緩慢迴應時,當我觸摸它是需要約3秒的響應,並且我試圖通過放置一個可運行的循環是20毫秒,運行時似乎需要1秒循環。android應用程序速度很慢,有2,500個圖像查看
public boolean onTouch(View v, MotionEvent event) {
if (v.getId()==R.id.imgTouch) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
y1 = event.getY();
txtTest.setText("" + x1+"/"+img[10][10].getDrawable().toString());
break;
case MotionEvent.ACTION_UP:
break;
}
}
return true;
}
private void LoadScreen() {
int w = (int) (screenWidth/mCols-0.75);
ImageView view;
for (int i = 0; i < mRows; i++) {
TableRow tr = new TableRow(getApplicationContext());
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for (int j = 0; j < mCols; j++) {
TableRow.LayoutParams lp = new TableRow.LayoutParams(w, w);
lp.setMargins(0,1, 1, 0);
view = new ImageView(getApplicationContext());
view.setLayoutParams(lp);
if (j==mCols-1 || i==mRows-1 || j==0 ||i==0)
view.setBackgroundColor(Color.RED);
else
view.setBackgroundColor(Color.rgb(220,225,219));
view.setImageResource(R.drawable.blank);
tr.addView(view);
img[i][j]=view;
}
tblScreen.addView(tr,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
}
}
表中的所有圖像是否始終可見?或者它滾動到其位置時是否可見? – Ercan
運行此遊戲時將會喜歡:https://www.flickr.com/photos/itismyaccount/24341123950/in/dateposted-public/,並且對於每個圖像視圖,背景顏色將從白色變爲黑色或其他。 –