01-05-2014 06:05 PM
In relation to my previous post, I'm trying to create a picture viewing UI that has a swipe gesture for going to the next/prev photo.
When the UI loads, it creates 5 image views and calls setImageSource on each of them to load their photo. Only one of them is visible on the screen. When the user goes to the next photo, I slide in the image view that was to the right.
The problem is, when the UI first loads and the first image appears, UI events don't seem to get processed -- perhaps until all 5 image views have finished loading their image? You can slide your finger across the screen and nothing happens. Then, a second or two later, the swipe gesture plays itself out.
Is this behavior expected? Do the image loads lock up the UI and cause it to stop processing events?
Solved! Go to Solution.
01-05-2014 06:25 PM
01-05-2014 08:08 PM
Yes, the images are large -- ones taken by the Z10 camera. (so, 8 megapixels?)
I realize the UI will need time to load the images, that's not really what my question is about... I'm more alarmed that the UI is locking up. I would think / hope that the UI would continue to run at 60 fps even if images were being loaded... and that the image views would simply remain non-visible until the images load and are ready to be displayed.
How does the threading work there? Possibly I need to look into asynchronous image loading? There's an "imageloader" example app that loads images (over the network I think) and then sends the image data to an ImageView. I suppose I'll have to try that as a next step...
01-05-2014 08:20 PM
Ok, so there's another clue. Even if I wait for several seconds after loading the UI to swipe to the next photo, there's still a lag of about 0.5 seconds before the images will start to slide. A guess is that the ImageView is somehow deferring some loading / rendering steps until the first time that image appears on the screen?
The reason I say that is that once the image to the right has slid onto the screen, you scan slide it back off the screen and then back onto the screen without any lock ups. I don't know whether explicit asychronous image loading code would help with that or not.
01-06-2014 01:46 PM
Hi Kyle, Interesting class, thanks. But I'm not sure how it applies to my problem.
01-08-2014 08:06 AM
01-12-2014 10:48 PM
The way I got around this was to use a bit of hackery. I tried the ImageTracker, but it didn't have any affect. My guess is that the lag isn't from the actual loading of the image from the SD card, as that happens prior to the swipe. Rather, it's when the image view first becomes visible on the screen.
To work around this, I display 1 horizontal pixel of the image on the screen, even if it's not supposed to be on the screen, and I set its opacity to 0.1 so that it's not perceptible. When I do this, the swipe event happens as one would expect without any lag prior to the next image appearing on the screen.