【发布时间】:2014-05-26 01:53:07
【问题描述】:
我在 Photoshop 中制作了一张藏宝图,并制作了一张带有彩色热点的透明图像,将其放在藏宝图上,以便可以点击。
当我点击彩色圆点(不可见)时,Android 会检测到点击的颜色并按照要求执行适当的方法。
现在我有一个图像视图,这将是我的播放器,我希望它每天移动到地图上的另一个彩色热点(每个热点代表一周中的一天)。
我有这个代码,但是位置太差了:
private void moveToColor(ImageView iv, int toColor) {
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.hotspots);
int width = bm.getWidth();
int height = bm.getHeight();
int[] pixels = new int[width * height];
bm.getPixels(pixels, 0, width, 0, 0, width, height);
for (int ix = 0; ix < width; ++ix) {
for (int iy = 0; iy < height; ++iy) {
if (toColor == bm.getPixel(ix, iy)) {
iv.animate().translationX((float)ix);
iv.animate().translationY((float)iy);
return;
}
}
}
}
有时它会将图像视图移动到靠近 toColor 的位置,有时它会完全关闭或什至不在地图上。
关于我如何做到这一点的任何指示。我用缓冲区 copypixelstobuffer 尝试过,但我不太了解它是如何工作的。因为上面很慢..
谢谢!
【问题讨论】:
标签: android bitmap imageview translate-animation