Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display different layouts with the ViewPager?

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

like image 246
Garry Avatar asked Dec 01 '25 02:12

Garry


1 Answers

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.

like image 105
Philipp Jahoda Avatar answered Dec 04 '25 01:12

Philipp Jahoda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!