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
0
votes
1 answer

ViewPager2 swipe not working inside RecyclerView

I have a parent RecyclerView that contains another RecyclerView and a ViewPager2 as it's children. The ViewPager2 child is like a Tinder Card Stack that swipes left and right, and works perfectly fine independently (when it is not in parent…
0
votes
1 answer

Layout width doesnt change when showing/hiding other UI elements

DISCLAIMER: This is part of a very large project, so I did what I can to simplify it. I am in the process of making a walk through Wizard in Xamarin.Android. I am trying to make it as flexible as possible where I can start the wizard activity and it…
0
votes
1 answer

How to prevent Android ViewPager2 scrolling automatically to a page with VideoView?

I have video view on a ViewPager2 page (at index=2). When I try to show the fragment containing the ViewPager2, the ViewPager2 auto scrolls to that page.
0
votes
1 answer

How to getItemAt(position) when using Viewpager2 with RecyclerViewAdapter

I implemented a pretty awesome viewpager2 by setting it to a recyclerView adapter, but I need more than just scrolling it. What I want: I need to get the views inside the layout which is adapted using RecyclerView.Adapter. Similarly the…
FawwazFaisal
  • 57
  • 2
  • 11
0
votes
0 answers

Glide: Image shriinks when scrolling

I am using Groupie RecyclerView to display some data, and used CardSlider Library with ViewPager2 with Glide to display multiple images. What I've been encountering is that After the images load the first name, the UI works fine displaying the…
0
votes
1 answer

ArcGIS map crashes under android ViewPager2

Dear StackOverflow Community! My question might be a rookie one, I feel like I'm missing something very basic. I tried to make an ArcGIS map work under an android ViewPager2 structure. The map diplays nicely but when I navigate away to another…
0
votes
0 answers

Can I use RecyclerView.Adapter as the adapter of a ViewPager2?

I am using a RecyclerView.Adapter as the adapter of a ViewPager2, but its appears don´t work properly, sometimes, when the user swipe, the viewpager skip items, for example it´s in 1 and the user swipe to see the item 2, but the ViewPager go to item…
0
votes
0 answers

ViewPager2 changes page automatically

My ViewPager changes pages by sliding to a page, sometimes it jumps page, for example it is on 1, and it goes to page 3, sometimes it changes without stopping for example from page 3 to 2, from 2 to 3, and so on. Listeners attached to ViewPager2 …
0
votes
1 answer

Fragments as Pages with ViewPager2

I have the following code (borrowed from the sunflower app) : const val FRAGMENT_A_PAGE_INDEX = 0 const val FRAGMENT_B_PAGE_INDEX = 1 class ViewPagerAdapter(fragment: Fragment): FragmentStateAdapter(fragment) { /** * Mapping of the…
ebeninki
  • 909
  • 1
  • 12
  • 34
0
votes
2 answers

Cannot figure out how to structure data for ViewPager2 from one Room entity using pojo

I am new to Android and need some help. I'm making an App which manages expenses. I have room database table 'expenses': CostEntry.java @Entity(tableName = "expenses") public class CostEntry { @PrimaryKey(autoGenerate = true) private int…
castaway
  • 5
  • 4
0
votes
0 answers

ViewPager2 TabLayout Fragment does not show ViewPager2 inner Fragment

I'm trying to make a fragment (GiornataFragment (DayFragment)) that contains a ViewPager2 element linked to a TabLayout. Inside the pages of ViewPager2 I would like to insert another fragment (PartitaFragment (MatchesFragment)) that contains only a…
0
votes
1 answer

How do you refresh a view each time a user switches to a tab in a ViewPager2?

I have the following FragmentStateAdapter: class TabPagerAdapter(activity: AppCompatActivity, private val itemsCount: Int) : FragmentStateAdapter(activity) { override fun getItemCount(): Int { return itemsCount } override fun…
Adrian Elder
  • 1,993
  • 3
  • 19
  • 38
0
votes
0 answers

In ViewPager2 recreate fragment at specific index

I'm using ViewPager2 and with FragmentStateAdapter to retain state of fragments. I show 2 fragments in the pager when user is loggedOut but when user logins again the i want to recreate only the 2nd fragment to show another fragment in its…
0
votes
1 answer

How to dynamically add and remove pages in Android ViewPager2?

Here is what I was trying to do. addNewQRCard() is onclick event fired by a button to add new images to viewpager. I have to always set the adapter to new items. But why in my case onStart() doesn't do that job. Please give me the best practice that…
0
votes
1 answer

How to Change Vertical ViewPager Swipe Angle

I'm using VerticalViewPager for swiping vertically through images. The vertical view pager is strict when it comes to swiping angle, which means it will proceed with swiping only if it is a perfectly vertical swipe (no change in x coordinate). But…
Tomin
  • 1,898
  • 3
  • 18
  • 23