Does the ViewPager
have to be the only object present inside the activity layout?
I'm trying to implement something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reader_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/page_viewer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Gallery
android:id="@+id/miniatures_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content" /></LinearLayout>
Where should I have a big pager scrolling in the top (and I have it) and a smaller gallery scrolling under that. This shows me only the pager and not the gallery. Any suggestion?
The ViewPager does not support
wrap_content
as it (usually) never have all its children loaded at the same time, and can therefore not get an appropriate size (the option would be to have a pager that changes size every time you have switched page).You can however set a precise dimension (e.g. 150dp) and
match_parent
works as well.You can also modify the dimensions dynamically from your code by changing the
height
-attribute in itsLayoutParams
.I solved the problem with a couple of hacks. Here is what it involves:
First, I needed a layout that would ignore
ViewPager
's height limit. Used it as a parent layout forViewPager
items.I then wrote the logic for resizing ViewPager:
Which I registered as global layout listener:
Assign layout weight to view pager as 1 & height = 0dp instead of wrap_content