Align the child views in center of the ViewPager android
For anyone upset that the OP didn't update his question with the solution here is a link that explains, with minimal effort, how to pull this off in XML: http://blog.neteril.org/blog/2013/10/14/android-tip-viewpager-with-protruding-children/
Basically when you declare your viewpager in XML, give it the same left and right padding and set android:clipToPadding="false". (The clipToPadding is missing in his xml sample and necessary to achieve this effect)
For one app I implemented similar the following way, with standard ViewPager
:
Make pages full-screen with the actual content in an inner layout. For example, make the full-screen layout a
RelativeLayout
with transparent background and the actual content anotherRelativeLayout
centered in the parent. If I remember right, the reason for this was that with just the inner layout as a page, theViewPager
would not have taken all the screen width on some devices such as Galaxy Nexus.Use
ViewPager.setPageMargin()
to set up a negative page margin i.e. how much of the next/previous page you want to show. Make sure it only overlaps the transparent region of the parent full-screen layout.Call
ViewPager.setOffscreenPageLimit()
to adjust the off-screen page count to at least2
from the default1
to ensure smooth paging by really creating the pages off-screen. Otherwise you will see next/previous pages being drawn while already partially showing on screen.