I had the same problem with the only difference that I had to show 3 pages at once (previous, current and next pages). After a very long study for a better solution, I think I found it. The solution is a combination of several answers here:
As @Paul Lammertsma's answer noted, Dave Smith's code on Mark Murphy's blog is the basis for the solution. The only problem for me was that the ViewPager was only at the top of the screen due to the size that they give in the XML file:
android:layout_width="150dp" android:layout_height="100dp"
This was bad for my purpose, as I was looking for something that would spread all over the screen. So I changed it to wrap the contents, as you can see here:
<com.example.nutrino_assignment.PagerContainer android:id="@+id/pager_container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#CCC"> <android.support.v4.view.ViewPager android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </com.example.nutrino_assignment.PagerContainer>
Now I have lost all the effect of what the textbook was trying to do. Using @andro answer , I was able to show more than 1 page at a time: exactly 2! Current and next. Did this by overriding it as follows:
@Override public float getPageWidth(int position) { return(0.9f); }
It was almost what I needed ... (although I think that it is enough for what you asked for), but for others who might need something like what I need: For the last part of the solution, I used idea in this answer , again @Paul Lammertsma. In the Dave Smith code, you will find this line in the onCreate method:
which I replaced with:
now on the first page it looks:
|view 1|view 2|view 3| |screen |
and on the second it looks like this:
|view 1|view 2|view 3| |screen |
Hope this helps someone! I wasted like 2 days on it ... Good luck.
goldengil Nov 15 '13 at 21:19 2013-11-15 21:19
source share