In this video we are going to create a simple example app that demonstrate how to use the ViewPager widget with TabLayout for creating swipe views in your android application.

ViewPager is a widget that contains many child views and each child view represent each page. You can use Fragments for representing each page in the swipe view. If there is a limited number of pages then you can use the FragmentPagerAdapter. If there is large number of pages then you have to use FragmentStatePagerAdapter.

In our example app we have only 3 pages and we use a common fragment for display each page.

You can easily configure a TabLayout with ViewPager widget by simple call the setUpWithPager method on the tabLayout and pass the ViewPager object as parameter.

In-order to set the Tab titles you have to override the getPageTitle method in the ViewPager Adapter class.

Like my Facebook page :
Subscribe My YouTube channel :

Nguồn:https://u-os.org/

Author

Write A Comment