bitmap - Android move ImageView to a specific pixel color -
i made treasure map in photoshop , made transparent image coloured hotspots put on treasure map can make clickable.
when click on colored dots (that invisible), android detects color clicked , appropriate methods, asked.
now have imageview, player, , each day want move colored hotspot on map (each hotspot represents day of week).
i have code, position way off:
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); (int ix = 0; ix < width; ++ix) { (int iy = 0; iy < height; ++iy) { if (tocolor == bm.getpixel(ix, iy)) { iv.animate().translationx((float)ix); iv.animate().translationy((float)iy); return; } } } }
sometimes move imageview close tocolor, , other times off or not on map.
any pointers on how this. tried buffer copypixelstobuffer, didn't understand how works. because above quite slow..
thanks!
sure off, read description of translationx
property carefully: http://developer.android.com/reference/android/view/view.html#attr_android:translationx
"this value added post-layout left property of view"
it's relative left of view, i.e. it's displacement, not absolute position. instead, use
iv.animate().x((float)ix);
and it's twin brother .y()
Comments
Post a Comment