【发布时间】:2016-04-10 02:34:16
【问题描述】:
TL;DR 我有很多按钮,我正在交换它们的图像。出于某种原因,我的代码只能在某些手机上运行,而不能在其他手机上运行。
我的应用使用以下代码来比较图像按钮上的图像:
onCreate:
redsquare = getResources().getDrawable(R.drawable.redsquare);
bitred = ((BitmapDrawable) redsquare).getBitmap();
onClick
(v 是点击的按钮)
ClickGround = v.getBackground(); //Get the background of button clicked
//the bitmap background of the button clicked
BitClick = ((BitmapDrawable) ClickGround).getBitmap();
然后,稍后在 onClick 中,我通过执行以下操作检查用户是否点击了 redSquare:
if (BitClick == bitred) { //Make sure it is the red square that user clicked
}
我已经在模拟器和华为手机上测试过,效果很好。当我在我的另一部手机(lg g3)上测试它时,if 语句没有通过。为什么结果不一样? 我的手机中的图像是否被弄乱了?
【问题讨论】:
-
为什么要将点击次数与背景而不是视图的 id 进行比较?
-
Why is this not working sometimes不是一个好的问题标题。
标签: java android if-statement optimization bitmap