There are many ways to improve the performance of a ViewPager
integrated with a ListView
.
First, change the PagerAdapter
from FragmentPagerAdapter
to FragmentStatePagerAdapter
. The difference is that you load 10 pages within the pager. And if you went through all the manager will only put the pages in onStop()
therefore it will reserve space. However using FragmentStatePagerAdapter
will destroy these pages but will save their instance using the onSaveInstanceState
method. So when you get back it won't take much time to load and you will be saving memory.
Usually FragmentPagerAdapter
is used with 3 pages or less.
The second way to improve performance (but it drains the battery faster) is adding this line to your AndroidManifest.xml
under your application tag:
android:hardwareAccelerated="true"
The third way is detecting the swipe gesture. You can do this by implementing onPageChangeListener
then in the implemented method onPageScrollStateChanged
you check if the page is Idle
then add the ListView
. Otherwise, stop the use of ListView
and scroll to the next page. Here is a better explanation of this point.
Hope some of these points can help you out to achieve better performance.