AndroidX Dependencies

To use ViewPager2, add the following AndroidX dependency to your project's build.gradle file:

 dependencies {
     implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha06'

Version 1.0.0-alpha06

July 2, 2019

androidx.viewpager2:viewpager2:1.0.0-alpha06 is released. The commits included in this version can be found here.

This is our last planned alpha before freezing the API and moving to beta - please provide us with API feedback.

New features

  • Foundations for improved Accessibility: ACTION_PAGE_RIGHT, ACTION_PAGE_DOWN, etc.

API changes

  • FragmentStateAdapter: non-primary-item Fragments are capped at STARTED, and their menuVisibility is set to false.
  • PageTransformer, MarginPageTransformer, CompositePageTransformer: documentation for positionfixed.

Bug fixes

  • currentItem after data-set change / adapter change fixed.
  • MarginPageTransformer with offscreenPageLimit issue fixed.
  • Accessibility actions while in FakeDrag behaviour fixed.

Version 1.0.0-alpha05

June 5, 2019

androidx.viewpager2:viewpager2:1.0.0-alpha05 is released. The commits included in this version can be found here.

New features

  • ItemDecorator introduced with a behaviour consistent with RecyclerView.
  • MarginPageTransformer introduced to provide an ability to create space between pages (outside of page inset).
  • CompositePageTransformer introduced to provide an ability to combine multiple PageTransformers.

API changes

  • FragmentStateAdapter#getItem method renamed to FragmentStateAdapter#createFragment - previous method name has proven to be a source of bugs in the past.
  • OFFSCREEN_PAGE_LIMIT_DEFAULT value changed from 0 to -1. No need for a client code change if the OFFSCREEN_PAGE_LIMIT_DEFAULTconstant used.

Bug fixes

  • getCurrentItem() behaviour corrected when SCROLL_STATE_SETTLING gets interrupted by a drag in the opposite direction.
  • FragmentStateAdapter class loader issues addressed in the "Don't keep activities" context.
  • setOffscreenPageLimit documentation improved.

Version 1.0.0-alpha04

May 7, 2019

androidx.viewpager2:viewpager2:1.0.0-alpha04 is released. The commits included in this version can be found here.

New features

  • offscreenPageLimit: allows for a tight control of the number of page Views / Fragments kept in the view hierarchy

API changes

  • orientation and isUserScrollable attributes are no longer part of SavedState
  • saveState and restoreState methods made final in FragmentStateAdapter
  • ViewPager2.Orientation and ViewPager2.ScrollState annotations made non-public

Bug fixes

  • SavedState: fixed an issue with restoring when Activity gets destroyed / recreated
  • SavedState: delayed restoring until the adapter is set
  • OnPageChangeCallback: minor edge cases fixed

Version 1.0.0-alpha03

April 3rd, 2019

androidx.viewpager2:viewpager2:1.0.0-alpha03 is released. The commits included in this version can be found here.

New features

  • Ability to programmatically scroll ViewPager2: fakeDragBy(offsetPx).

API changes

  • FragmentStateAdapter now requires a Lifecycle object. Two utility constructors added to obtain it from the host FragmentActivity or the host Fragment.

Bug fixes

  • Numerous Fragment support fixes:
    • handling dataset updates while minimised, or during a screen rotation;
    • removing irrelevant Fragments after rotation;
    • removing saved state of removed items.
  • PageChangeCallback: fixed page offset calculation for pages with margins.

Version 1.0.0-alpha02

March 13, 2019

androidx.viewpager2:viewpager2:1.0.0-alpha02 is released. The full list of commits included in this version can be found here.

New features

  • Ability to disable user input (setUserInputEnabled, isUserInputEnabled)

API changes

  • ViewPager2 class final

Bug fixes

  • FragmentStateAdapter stability fixes

Version 1.0.0-alpha01

February 7, 2019

androidx.viewpager2:viewpager2 1.0.0-alpha01 is released. This is the first release of ViewPager2.

New features

  • Comparing to its predecessor (VP1):
    • Right-to-left (RTL) layout support
    • Vertical orientation support
    • notifyDataSetChanged fully functional (VP1 bugs addressed)

API changes

  • FragmentStateAdapter replaces FragmentStatePagerAdapter
  • RecyclerView.Adapter replaces PagerAdapter
  • registerOnPageChangeCallback replaces addPageChangeListener

Known issues

  • clipToPadding
  • no fakeDrag
  • JavaDoc
  • nested scrolling parallel to orientation
  • no offscreen limit control
  • needs better TabLayout integration
  • no pageWidth setter (forced 100%/100%)
  • page transformer: no hardware/software layer choice; no reverse drawing order
  • keep current item visible when inserting a page before current
  • keyboard navigation needs work
  • FragmentStateAdapter stability / performance improvements coming