I have been working on a new Android application and I wanted to implement a ViewPager as a Header in a ListView.
The ViewPager is a series of Images loaded asynchronously using theSquare Picasso library.
The problem I ran into is that even though I am adding the ViewPager to the ListView via
myListView.addHeaderView(theViewPager);, upon rendering the header view was not visible. It was as if it had 0 width and height (hint hint).
When I pulled my ViewPager out by itself than it worked just fine.
If I implemented an ImageView with a static background drawable and attached that to the ListView header than it worked.
Both of these experiments pushed me in the direction of learning that when the header view is added the ListView really wants to know the layout metrics of the header view and is not cool with having to know it after the fact (because the images are loaded asynchronously).
This solution is to fix the ViewPager (header) layout params, which can be done in XML or programmatically.
My programmatic solution is to fix the width of the ViewPager to the device width and hard-code the height, which is acceptable for my scenario.