How to display different layouts with the ViewPager?

10,685

For a ViewPager, you will need Fragments instead of Activities.

Here is how to implement a ViewPager with Fragments and different layouts: How to implement a ViewPager with different Fragments / Layouts

The basic idea is that you create a Fragment for every layout you have, and then inside your FragmentPagerAdapter, load the correct Fragment depending on which page you are currently on.

Share:
10,685
Garry
Author by

Garry

Updated on June 05, 2022

Comments

  • Garry
    Garry almost 2 years

    In Xamarin, I currently have two different activities and I would like to combine these together and use a ViewPager.

    One activity uses the following content view: SetContentView(Resource.Layout.MapWithOverlayLayout);

    The second activity uses the following content view: SetContentView(Resource.Layout.HomeScreen);

    Can I please have some help to code a simple ViewPager that can add the two above content views into a ViewPager and then show each of these content views via code?

    Thanks in advance