ViewPager2
Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |
---|---|---|---|---|
May 14, 2024 | 1.1.0 | - | - | - |
AndroidX Dependencies
To use ViewPager2
, add the following AndroidX dependency to your project's
build.gradle
file:
Groovy
dependencies { implementation "androidx.viewpager2:viewpager2:1.1.0" }
Kotlin
dependencies { implementation("androidx.viewpager2:viewpager2:1.1.0") }
Feedback
Your feedback helps make Jetpack better. Let us know if you discover new issues or have ideas for improving this library. Please take a look at the existing issues in this library before you create a new one. You can add your vote to an existing issue by clicking the star button.
See the Issue Tracker documentation for more information.
Version 1.1.0
Version 1.1.0
May 14, 2024
androidx.viewpager2:viewpager2:1.1.0
is released. Version 1.1.0 contains these commits.
Important changes since 1.0.0
- Fixes crashes when used with RecyclerView
1.3.1-rc01
or higher. ViewPager2
now correctly populates theCollectionInfo
andCollectionItemInfo
that RecyclerView1.2.0-alpha02
and higher no longer populate by default.- Added
FragmentTransactionCallback
interface for listening to fragment lifecycle changes that happen insideFragmentStateAdapter
. - Fixed
FragmentStateAdapter
issue with initial fragment menu visibility when adding a fragment to theFragmentManager
. - Fixed dispatch of window insets: all pages now get the same insets. Due to how
WindowInsets
are dispatched on old API versions (< API 30) that can prevent insets from being available to sibling views, you must opt into this fix viaWindowInsetsApplier.install(viewPager2)
if you want to apply insets on < API 30 devices.
Version 1.1.0-rc01
May 1, 2024
androidx.viewpager2:viewpager2:1.1.0-rc01
is released with no notable changes since 1.1.0-beta02. Version 1.1.0-rc01 contains these commits.
Version 1.1.0-beta02
May 24, 2023
androidx.viewpager2:viewpager2:1.1.0-beta02
is released. Version 1.1.0-beta02 contains these commits.
API Changes
- Added Fragment state saving callbacks to
FragmentTransactionCallback
. (I45b90) ViewPager2
now no longer tries to fix the brokenWindowInsets
dispatch of old API versions (< 30), because the fix itself can be harmful to siblings ofViewPager2
. The fix is still available, but has become an opt-in so developers can decide on a case by case basis. Enable the fix by callingWindowInsetsApplier.install(viewPager2))
. (Ic9a85)
Bug Fixes
- Fix compatibility issues with newer versions of
RecyclerView
. Users of this version ofViewPager2
should update to at leastRecyclerView
1.3.1-rc01.
Version 1.1.0-beta01
August 4, 2021
androidx.viewpager2:viewpager2:1.1.0-beta01
is released. Version 1.1.0-beta01 contains these commits.
API Changes
Upgrade androidx to use Kotlin 1.4 (Id6471, b/165307851, b/165300826)
Move to targeting Java 8 for all androidx libraries (2923f39)
Bug Fixes
- Fixed dispatch of window insets, all pages now get the same insets. (I47fef)
Version 1.1.0-alpha01
April 1, 2020
androidx.viewpager2:viewpager2:1.1.0-alpha01
is released. Version 1.1.0-alpha01 contains these commits.
This release accompanies a change in RecyclerView 1.2.0-alpha02 by populating CollectionInfo
and CollectionItemInfo
that RecyclerView
no longer provides by default. When updating to RecyclerView 1.2.0-alpha02
also update ViewPager2
to prevent Accessibility regressions.
New Features
- Added
FragmentTransactionCallback
interface for listening to fragment lifecycle changes that happen insideFragmentStateAdapter
. (Ibda77)
Bug Fixes
- Fixed
FragmentStateAdapter
issue with initial fragment menu visibility when adding a fragment to theFragmentManager
. (I9d2ff, b/144442240)
Version 1.0.0
Version 1.0.0
November 20, 2019
androidx.viewpager2:viewpager2:1.0.0
is released with no changes from 1.0.0-rc01. Version 1.0.0 contains these commits.
Major features of 1.0.0
- Improvements from the previous ViewPager implementation:
- RTL (right-to-left) layout support
- Vertical orientation support
- Reliable
Fragment
support (including handling changes to the underlyingFragment
collection) - Dataset change animations (including
DiffUtil
support)
- Easy migration from the previous
ViewPager
implementation (API parity where possible). See the migration guide and the sample app.
See the guide on using ViewPager2 to slide between Fragments.
Version 1.0.0-rc01
October 23, 2019
androidx.viewpager2:viewpager2:1.0.0-rc01
is released with no changes since 1.0.0-beta05
. Version 1.0.0-rc01 contains these commits.
Version 1.0.0-beta05
October 9, 2019
androidx.viewpager2:viewpager2:1.0.0-beta05
is released. Version 1.0.0-beta05 contains these commits.
Bug fixes
- Fix for
requestFocus
on an off-screen page causing a page change. The behaviour is now consistent with the original ViewPager. (b/140656866) - Fix for
focus
remaining on an off-screen page after a page change. Focus is now cleared when changing the page. (b/140656866) - Fix for ordering of
Fragment
pause / resume transactions when changing the page (we now always pause the old primary item before resuming the new one). (b/139489059) - Fix for
canScrollHorizontally(int)
andcanScrollVertically(int)
- they now return whether ViewPager2 can scroll in the given direction. (b/141848404) - An issue in SwipeRefreshLayout was fixed to work better with ViewPager2.
Version 1.0.0-beta04
September 5, 2019
androidx.viewpager2:viewpager2:1.0.0-beta04
is released. The commits included in this version can be found here.
Bug fixes
- Fix for
FragmentStateAdapter
edge-case issue withFragment
back stack. (b/139095195) - Fix for
EditText
with certain attribute configurations causing a scroll/page jump on typing/focus. (b/138044582, b/139432498) - Fix for an issue with
ItemDecoration
instances, and a workaround for overscroll indicator positioning. (b/139012032) - A number of issues were fixed in other components to work better with
ViewPager2
: RecyclerView, NestedScrollView, and Navigation.
Version 1.0.0-beta03
August 7, 2019
androidx.viewpager2:viewpager2:1.0.0-beta03
is released. The commits included in this version can be found here.
Bug fixes
- Fix for
FragmentStateAdapter
issue with transientFragment
state. b/134246546 - Fix for
currentItem
andscrollState
issues when a data-set is changed during a smooth-scroll (edge cases addressed). b/137642608 - Fix for
PageTransformer
(includingMarginPageTransformer
) animations conflicting with data-set change animations. b/134658996 - Fix for smooth-scroll animations in large datasets (
float
integer value limit). b/134858960
Version 1.0.0-beta02
July 19, 2019
androidx.viewpager2:viewpager2:1.0.0-beta02
is released. The commits included in this version can be found here.
Bug fixes
- Removed unintentional jacoco dependency that was introduced in
1.0.0-beta01
. (b/137782951)
Version 1.0.0-beta01
July 17, 2019
androidx.viewpager2:viewpager2:1.0.0-beta01
is released. The commits included in this version can be found here.
Bug fixes
- Fix for
ViewPager2.updateCurrentItem
crash while scrolling and updating data-set - Fix for
NullPointerException
crash related toViewPager2.isLayoutRtl
TOUCH_SLOP_PAGING
now a default touch slopOnPageChangeCallback
events fixed for empty adapters (page0
instead of-1
for parity withViewPager1
)
Known issues
- We are still working on the remaining open issues before moving to Stable
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-itemFragment
s are capped atSTARTED
, and theirmenuVisibility
is set to false.PageTransformer
,MarginPageTransformer
,CompositePageTransformer
: documentation forposition
fixed.
Bug fixes
currentItem
after data-set change / adapter change fixed.MarginPageTransformer
withoffscreenPageLimit
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 withRecyclerView
.MarginPageTransformer
introduced to provide an ability to create space between pages (outside of page inset).CompositePageTransformer
introduced to provide an ability to combine multiplePageTransformer
s.
API changes
FragmentStateAdapter#getItem
method renamed toFragmentStateAdapter#createFragment
- previous method name has proven to be a source of bugs in the past.OFFSCREEN_PAGE_LIMIT_DEFAULT
value changed from0
to-1
. No need for a client code change if theOFFSCREEN_PAGE_LIMIT_DEFAULT
constant used.
Bug fixes
getCurrentItem()
behaviour corrected whenSCROLL_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 pageView
s /Fragment
s kept in the view hierarchy
API changes
orientation
andisUserScrollable
attributes are no longer part ofSavedState
saveState
andrestoreState
methods made final inFragmentStateAdapter
ViewPager2.Orientation
andViewPager2.ScrollState
annotations made non-public
Bug fixes
SavedState
: fixed an issue with restoring whenActivity
gets destroyed / recreatedSavedState
: delayed restoring until the adapter is setOnPageChangeCallback
: 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 aLifecycle
object. Two utility constructors added to obtain it from the hostFragmentActivity
or the hostFragment
.
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
android.support.v4.view.ViewPager
(VP1):- Right-to-left (RTL) layout support
- Vertical orientation support
notifyDataSetChanged
fully functional (VP1 bugs addressed)
API changes
FragmentStateAdapter
replacesFragmentStatePagerAdapter
RecyclerView.Adapter
replacesPagerAdapter
registerOnPageChangeCallback
replacesaddPageChangeListener
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