views:

568

answers:

1

Hello, everyone,

For the application I'm currently working on, I created something like ImageSwitcher for multiple images (imagine iPhone's UIScrollView with paging enabled).

At first, I hardcoded some ImageViews and loaded their drawable resources on creation/inflation, but after some tweaks (and what I thought were improvements), I reduced the needed views to 3, of which 2 are ImageViews used for displaying of the current page and animating between current and new page.

With this change, I began to use setImageResource/setImageDrawable for the dynamic loading of the new image in my 2 ImageViews before sliding through pages (I am using PNG files, sized for HVGA displays).

To my disappointment, the performance got worse, to the extent of feeling some lag when sliding faster through the pages. A quick look in TraceView revealed that 17.4% of total time while using the app, over 5 times more than the next heavy method, was consumed from BitmapFactory.nativeDecodeAsset, called by my dynamic setting of drawable resource.

I'm thinking of ways to circumvent this, and I want to do it in the best way possible, so any suggestions are welcome.

+1  A: 

In which format do you have the images?

Android works natively with RGB565 images, so if you can convert your images to that format, decoding will be much faster.

Lucas S.
Hello, I've mentioned that I get the images in PNG format, but I don't know if the buffer for these files is RGB 565 (that's 16-bit Highcolor, right?).I tried to load bitmap directly from image converted to .rgb565, but Android's BitmapFactory doesn't seem to work with it.Anyway, thanks for the idea.
Dimitar Dimitrov