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

Display 2D array data in ViewPager2

My 2D array has 5x3. In array I have stored id, name, image source string. I trying to put these values in Adapter to make newInstance, but all values in Fragment are passed as null. My Adapter: private class ScreenSlidePagerAdapter extends…
0
votes
1 answer

TabLayoutMediator Infinite Tabs

I'm trying to write a horizontal datepicker using Tabs with ViewPager2 and came across TabLayoutMediator. It seems like the perfect solution for what I am trying to accomplish but when I call attach() on the TabLayouMediator, it will lock the main…
0
votes
0 answers

How to open next activity by clicking specific image in viewpager2?

I am a newbie, sorry for my ignorance. I have some difficulties with viewpager2. Could anyone let me know how to open specific activity by clicking a specific image in viewpager2? My viewPager consists of four images. I got this code online. It…
0
votes
2 answers

Calling mainActivity method through Fragment

I have implemented fragment in viewpager and Fragment has some buttons. Also viewpager is in activity_main layout. I want that when button is clicked then it implement a method which is mentioned in mainActivity.java. How can I do this? I am a…
0
votes
2 answers

Animation not working while loading from XML in Android

I am trying to do some animation inside ViewPager2 with Fragments. But the problem is when I load the animation from XML, it is working for the first time. After swiping left/right in ViewPager and going back to the same page that animation is not…
0
votes
0 answers

ViewPager2 disable swipe action

I'm using the new ViewPager2 in a project and I need to disable the swipe action. Have to restrict the user to change tabs only pressing the TabLayout buttons. With the default ViewPager you can achieve this by making your custom ViewPager and…
0
votes
1 answer

Progress Bar not showing in inside CardView

I have a viewpager which I use to display cards of offers, now, for some reason , when I click each card, it does not show me the progressbar I setup
0
votes
1 answer

Why does my vertical RecyclerView in my horizontal ViewPager2 not scroll?

My RecyclerView in ViewPager2 does not scroll. The documentation of ViewPager2 has a section about nested scrollable elements, but it is about elements having the same orientation as the ViewPager2. I have different orientations in ViewPager2…
Zezi Reeds
  • 1,286
  • 1
  • 16
  • 29
0
votes
1 answer

How to add left and right edge effect when ViewPager2's user input is disabled

Since my app lags during left/right transitions between fragments in a ViewPager2, I decided to disable its native swipe function with viewPager2!!.isUserInputEnabled=false. However, this also disabled the blue colored edge effect when swiping…
0
votes
2 answers

ViewPager2 adapters - difference between FragmentActivity / Fragment / FragmentManager

I noticed in this ViewPager2 video that there are 3 different ways of declaring an adapter with Fragments. What's the difference between them and which 1 should be used for swipe views with tabs using ViewPager2? Option 1 (recommended) class…
wbk727
  • 8,017
  • 12
  • 61
  • 125
0
votes
2 answers

ViewPager of React Native gives error :: 'ViewPagerAndroid has been removed from React Native'

I am trying to use the View Pager on React Native and I am using the reference link for…
akash89
  • 881
  • 3
  • 12
  • 31
0
votes
1 answer

Using ViewPager2 in an Existing Fragment

I have Created a Fragment for my bottom Tab bar, The tab bar has four fragments, In one of my fragments, I am in need of Slider to view testimonials of people one by one. In this case, I have used the ViewPager2 functionality to work on the slider,…
0
votes
3 answers

Viewpager2 swipe gesture only horizontally Android

How can I prevent diagonal swipe on Viewpager2, only allow to swipe if gesture is strictly horizontally. I dot not want this I want this
0
votes
1 answer

ViewPager2 error androidx....RecycleView.Adapter) in ViewPager2 can not be applied

I converted my old viewPager adapter to the new viewPager2 adapter. I get error when i setAdapter to viewPager2. setAdapter(androidx.viewpager.widget.RecycleView.Adapter) in ViewPager2 can not be applied to ViewPagerAdapter my…
Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
0
votes
0 answers

Put a vertical viewpager just showing items, within a recyclerview

I'm hoping someone can show me the ropes of hopefully ViewPager2, but I'm basically in need of making a viewpager where I can swipe between different images. I will have a category, let's call it Category A. Category A can have multiple items in…