Questions tagged [android-viewpager2]

ViewPager2 is the replacement of ViewPager, addressing most of its predecessor's pain-points, including right-to-left layout support, vertical orientation and modifiable Fragment collections.

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 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

Useful links:

Official documentation

Official sample

Fundamental Stack Overflow answer

740 questions
7
votes
1 answer

Nested viewpager2

I'm trying to implement layout like this: I attached sample project: https://drive.google.com/file/d/1jEKOONMWN3MblLN1EmePsWTWNCNQVfN-/view?usp=sharing The problem I have is that second view pager does not react to touch events. Ideally, if user…
Ivan Škugor
  • 558
  • 1
  • 6
  • 21
7
votes
2 answers

Navigate from ViewPager2 to another fragment using jetpack

I have single activity, FragmentHome contains viewpager2. Inside of viewpager there is FirstFragment. when I want to navigate from FirstFragment to SecondFragment which is not in viewpager2 it throws java.lang.IllegalArgumentException:…
7
votes
3 answers

FragmentStateAdapter for ViewPager2 notifyItemChanged not working as expected

I am using ViewPager2 with FragmentStateAdapter and i am calling notifyItemChanged(position). But as expected createFragment method not calling again. Is it is the intended behavior or bug, what should I do My Code is class…
Karthick Ramanathan
  • 642
  • 3
  • 9
  • 20
7
votes
2 answers

ViewPager2 preloaing next fragment even when offsetlimit is the default(0)

I am facing this rather strange problem with viewPager2. I did some reading and found out that viewPager2 has a default offset limit of 0 which is perfect for my application. I'm using it with a tab layout and I have 3 fragments (Home, Profile,…
Tanzim Chowdhury
  • 3,020
  • 2
  • 9
  • 21
7
votes
4 answers

Scrolling behaviour conflicts with a child RecyclerView and a parent Viewpager2

I have a vertical scrolling ViewPager2 and the last children contains a RecyclerView scrolling on the same direction. This is causing a conflicting behaviour, the ViewPager2 always steal the scroll event when I am at the page containing this…
6
votes
2 answers

AppBarLayout with scrolling behavior alternative/ sticky view on scrolling/ large height AppBarLayout causing weird scroll

Video of my current state,for better understanding of my situation: video everything above RecyclerView is inside AppbarLayout Example of reddit app with similar behavior: video Goal: 1-Implement scrolling screen with views in order from top to…
6
votes
1 answer

Android. How to load paging data from specific position with Paging 3?

I'm using paging3 for showing endless list in RecyclerView. When I click in specific item I need to show detail fragment. The detail fragment contains a view pager whose adapter is also PagingDataAdapter. That is, a fragment with detailed…
6
votes
0 answers

Backstack like instagram with viewpager and BottomNavigationBar

I have created an android app (Sample APK & Github Repo) where I implement a BottomNavigationBar with ViewPager. Navigation is ok but I don't know how to handle the back stack in a viewpager like Instagram. I tried the below code but this way I have…
6
votes
3 answers

ViewPager2 doesn't show correct Fragment on slow devices or when debugging

I'm using ViewPager2 with TabLayout and FragmentStateAdapter to display Fragments in tabs. I found out that when I run it on slower devices (ie. Nexus 5X) or when I put a breakpoint to createFragment() method, after I change to some later tab with…
Micer
  • 8,731
  • 3
  • 79
  • 73
6
votes
2 answers

Android ViewPager2 - how to detect user initiated page change

I have the ViewPager2 callback setup but need to detect when a user initiated page change has completed. The callback won't differentiate between user initiated and code initiated. Here's what I have now: ViewPager2.OnPageChangeCallback…
lilbiscuit
  • 2,109
  • 6
  • 32
  • 53
6
votes
2 answers

Start child fragment in ViewPager2

I'm using ViewPager2 with FragmentStateAdapter. Basic 3 fragments (A-B-C). It means, you can scroll from A to B, B to C What I want to do? From fragment B start child fragment D (A-B-C) | D From fragment B start fragment D, when the user…
Thomas Banderas
  • 1,681
  • 1
  • 21
  • 43
6
votes
2 answers

How to use PagerTitleStrip in ViewPager2?

I have a standard implementation of PagerTitleStrip in ViewPager but it cannot work in ViewPager2. If I want to migrate to ViewPager2, how should I implement PagerTitleStrip within ViewPager2? I found solution and many detailed info regarding how to…
Neoh
  • 15,906
  • 14
  • 66
  • 78
6
votes
2 answers

ViewPager2 conflicting with SwipeRefreshLayout

I'm using Horizontal ViewPager2 which has 4 fragments inside. Each fragment has SwipeRefreshLayout on a RecyclerView. The issue that I'm facing is that when RecyclerView is at top position then onClick on any item is list is not working. If I scroll…
6
votes
3 answers

Google Map + ViewPager2 swiping conflict

Anyone dealing with ViewPager2 + Fragments + GoogleMap? I've ran into a really interesting issue, inside my viewpager i have two tabs that each render fragments. One of the fragments spawns a google map. When i try maneuvering through that map i get…
6
votes
1 answer

Viewpager2 transistion stuck halfway when slide opened using setCurrentItem

The app uses android viewpager2 (androidx.viewpager2:viewpager2:1.0.0-beta04) to show slides. Each slide have video on its top half and text on its bottom half. Each slide is built using same fragment class (code given below) If slided one by one,…
Sumit
  • 401
  • 2
  • 6
  • 21