通过玩代码,我发现这两个代码块似乎具有不同的速度。注意 if 语句的不同之处。两者都在我的模拟器上编译没有问题,但第二个代码块略有滞后。有谁知道为什么?(我很少使用第二块的结构)
Bitmap temp;//td.getPlayClicked(), getPlayUnclicked(),etc. returns a different Bitmap
Canvas canvas;//this runs fine, it is instantiated in my thread class, I'm just showing what type each object is.
for(int alg=0;alg<td.getBitmaps();alg++){
if(temp.equals(td.getPlayClicked())||temp.equals(td.getPlayUnclicked())){
canvas.drawBitmap(drawing.get(alg),this.getWidth()/2-td.getPlayClicked().getWidth()/2, this.getHeight()*2/3, null);
}
}
相对:
for(int alg=0;alg<td.getBitmaps();alg++){
if(drawing.get(alg).equals(td.getClicked()?td.getPlayClicked():td.getPlayUnclicked())){
canvas.drawBitmap(drawing.get(alg),this.getWidth()/2-td.getPlayClicked().getWidth()/2, this.getHeight()*2/3, null);
}
}