Optimizing paging between ImageViews in Android?

For the application I'm currently working on, I created something like ImageSwitcher

for multiple images (let's say an iPhone UIScrollView

with paging support).

I first hard-coded some ImageViews

and loaded their resources on create / inflation, but after some tweaking (and there were improvements I thought), I reduced the required views to 3, of which 2 are ImageViews

used to display the current page and animate the current and new pages.

With this change, I started using setImageResource

/ setImageDrawable

to dynamically load a new image in my 2 ImageViews

before sliding through the pages (I am using PNG files which are sized for HVGA displays).

To my disappointment, performance has deteriorated, as much as possible lag when accelerating through the pages. A quick look in TraceView

showed that 17.4% of the total time when using the app 5x more than the following heavy method was consumed from BitmapFactory.nativeDecodeAsset

caused by my dynamically setting a resource to allocate.

I am thinking of ways to get around this and I want to do it in the best possible way, so any suggestions are greatly appreciated.


source to share

1 answer

What format do you have images in?

Android works with RGB565 images, so if you can convert images to this format, the decoding will be much faster.



All Articles