Displaying a stack of images

102 Views Asked by At

Given:

  • A number of images (10 - 15) residing in assets folder (as practice shows, the better approach is to keep high-resolution images in assets)
  • Android UI thread (caching drawables in advance is already made in a background thread)

The issue:

Need to display all the images one on another smoothly and not blocking UI thread after the images are drawn.

Already used approaches:

  • Dynamically create a required number of ImageView and then call .setImageDrawable(). This takes a lot of time but the worst thing is that the UI thread is being blocked even after all the images are drawn on their ImageView.
  • Create a LayerDrawable object and pass as argument an array of the required Drawables. Then put it on an ImageView also by calling .setImageDrawable(). This option behaves the same like the one described above.

Is there a way to solve this issue? Or Android devices not capable to cope with it?

2

There are 2 best solutions below

6
On

If you are requiring a smooth transition between images, please try viewFlipper https://developer.android.com/reference/android/widget/ViewFlipper.html

Basically you can add imageView inside the viewflipper and start animation to move from previous to next image. I am not sure if you need user interactions like scrolling or not. You can try viewPager if user need to scroll betweens images.

Please note that Glide does provide some transition effects for switching between placeholder and image to display. But transition between images are not included, you can have a look here http://bumptech.github.io/glide/doc/transitions.html

I hope this helps because i am not sured that if you are asking the transition between images or rendering images.

3
On

Try Picasso library:

http://square.github.io/picasso/

It has support for resources:

Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);