Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Optimization of heavy view hierarchy

OP surlac

9th May 2014, 08:44 PM   |  #1  
OP Member
Thanks Meter: 3
 
36 posts
Join Date:Joined: Feb 2012
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
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes