Multiple pages at the same time on a ViewPager
Solution 1:
Please have a look at the getPageWidth
Method in the corresponding PagerAdapter
. Override it and return e.g. 0.8f
to have all child pages span only 80% of the ViewPager's width.
More info: http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html#getPageWidth(int)
Solution 2:
See my more up-to-date answer here: Can ViewPager have multiple views in per page?
I discovered that a perhaps even simpler solution through specifying a negative margin for the ViewPager. I've created the MultiViewPager project on GitHub, which you may want to take a look at:
https://github.com/Pixplicity/MultiViewPager
Although this question specifically asks for a solution without edge effect, some answers here propose the workaround by CommonsWare, such as the suggestion by kaw.
There are various problems with touch handling and hardware acceleration with that particular solution. A simpler and more elegant solution, in my opinion, is to specify a negative margin for the ViewPager:
ViewPager.setPageMargin(
getResources().getDimensionPixelOffset(R.dimen.viewpager_margin));
I then specified this dimension in my dimens.xml
:
<dimen name="viewpager_margin">-64dp</dimen>
To compensate for overlapping pages, each page's content view has the opposite margin:
android:layout_marginLeft="@dimen/viewpager_margin_fix"
android:layout_marginRight="@dimen/viewpager_margin_fix"
Again in dimens.xml
:
<dimen name="viewpager_margin_fix">32dp</dimen>
(Note that the viewpager_margin_fix
dimension is half that of the absolute viewpager_margin
dimension.)
We implemented this in the Dutch newspaper app De Telegraaf Krant:
Solution 3:
You have to override the getPageWidth()
method on the viewpager's Adapter. For Example:
@Override
public float getPageWidth(int position) {
return 0.9f;
}
Try that code in your Adapter and then you'll understand.
Solution 4:
See that blog entry.
PagerContainer technique is solved my problem.
EDIT:
I found same answer.
How to migrate from Gallery to HorizontalScrollView & ViewPager?