I am working on a 360 degree image rotator in Android as shown in this link:
http://developer.apple.com/safaridemos/showcase/threesixty/
For this use case, I am simply using more than 40 images to be shown at different angles when user scrolls horizontally.
using this code:
public boolean onScroll
(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
Log.i(TAG, "distanceX = "+distanceX);
if(distanceX > 3){
if(imageCounter < imgArr.length - 1){
imageCounter++;
}else{
imageCounter = 0;
}
imageSwitcher.setImageResource(imgArr[imageCounter]);
}else if(distanceX < -3){
if(imageCounter > 0){
imageCounter--;
}else{
imageCounter = imgArr.length - 1;
}
imageSwitcher.setImageResource(imgArr[imageCounter]);
}
return true;
}
My problem is that the switching in images is not smooth enough. A look at Logcat tells that with every 2-3 switches in images, Garbage collector does its work and takes around 20 milliseconds in finishing its job everytime. These few milliseconds are causing problem in attaining a smooth 360 degree rotation.
You could try changing imgArr to a Bitmap array and then using setImageBitmap instead of setImageResource. If you are only using 40 images you should be able to fit all those in memory. There will be a slight delay on startup (should be <1 second on a newer phone) to load all the Bitmaps but it should make it smooth, the GC will not collect the Bitmaps if they are still referenced.
It may not even be the GC to be honest. Using setImageResource causes the Bitmaps to be read and decoded on the UI thread, which may be causing your latency issues. This is noted in the docs here.