Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ViewPager have multiple views in per page?

After trying out the Gallery and Horizontal Scroll View, I found that the View Pager does what I need but with one minor thing missing. Can the View Pager have multiple views per page?

I know that View Pager shows only 1 view/page per swipe. I was wondering if I can limit my views width so my 2nd view following it will show?

For example: I have 3 views and I want the screen to show view 1 and part of view 2 so the user knows there is more content so they can swipe to view 2.

|view 1|view 2|view 3| |screen   | 
like image 640
CLDev Avatar asked Feb 27 '12 16:02

CLDev


People also ask

Is ViewPager deprecated?

This function is deprecated. Set a drawable that will be used to fill the margin between pages. Set a drawable that will be used to fill the margin between pages. reverseDrawingOrder: Boolean, transformer: ViewPager.

What is difference between ViewPager and ViewPager2?

ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager . If your app already uses ViewPager , read this page to learn more about migrating to ViewPager2 .

Can we add activity in ViewPager?

You can't use ViewPager to swipe between Activities . You need to convert each of you five Activities into Fragments , then combine everything in one FragmentActivity with the Adapter you use with ViewPager .

What is the use of ViewPager in image slider?

ViewPager is a class in Java that is used in conjunction with Fragments. It is mostly used for designing the UI of the app.


1 Answers

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 MultiViewPager expects a child view for specifying the dimension, the principle revolves around setting the page margin:

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:

Phone example in De Telegraaf KrantTablet example

like image 112
Paul Lammertsma Avatar answered Oct 09 '22 05:10

Paul Lammertsma