Remove All Ads from XDA

[Q] Optimization of heavy view hierarchy

58 posts
Thanks Meter: 6
By surlac, Member on 9th May 2014, 08:44 PM
Post Reply Email Thread
I have 4 screens where user can swipe between. I use ViewPager and inflate ViewGroup in instantiateItem(). Everything is perfect if all childs of ViewGroups are 'lightweight', but when background and couple images added on each of screens the swipe animation becomes jerky.
The first thing I did to optimize it is making snapshot of view hierarchy and replacing the whole view hierarchy with single ImageView displaying snapshot. It performs good, and swipe is smooth, but on some devices it causes OutOfMemoryError.

I believe the problem is that ViewPager loads current, idx+1 and idx-1 pages, and if display is for example 1920 x 1200px (Asus Transformer TF700), and each px supports transparency, then 1920x1200x4=9MB for each page, and if 3 pages are loaded then 9*3=27MB, it is > 16MB (heap limit), and OutOfMemoryError will be thrown.

How can I show these 4 pages without causing the Error and make swipe smooth at the same time?
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes