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

Viewpager2 dependency causes crash at launch

Adding the Viewpager2 dependency makes my app crash at launch. When my dependencies looks like this, everything works exactly as it should. dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // implementation…
Reynard
  • 111
  • 1
  • 1
  • 4
0
votes
2 answers

ViewPager2 OnApplyWindowInsetsListener not called

I have a FAB on a Fragment in a ViewPager2 which should respect the window insets when going edge-to-edge. I'm adding a OnApplyWindowInsetsListener on the FAB which updates its margin. This works fine when using the old ViewPager. When updating to…
hardysim
  • 2,756
  • 2
  • 25
  • 52
0
votes
1 answer

ViewPager2 when set height then swipe not work

Android Studio 3.6 I want to use ViewPager2 to swipe images: here xml layout:
Alexei
  • 14,350
  • 37
  • 121
  • 240
0
votes
2 answers

Add androidx.viewpager2 to android.mk file

Trying to add androidx.viewpager2 to android.mk as below: LOCAL_STATIC_ANDROID_LIBRARIES += \ androidx.viewpager2_viewpager2 Not able to build code using MMA command and gives below error. ninja: error: …
0
votes
1 answer

Can't use androidx.fragment.app.FragmentManager in ViewPager2

Android Studio 3.6 I want to use ViewPager2 with Fragments (swipe elements) app/build.gradle: implementation fileTree(dir: 'libs', include: ['*.jar']) implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true; } …
Alexei
  • 14,350
  • 37
  • 121
  • 240
0
votes
1 answer

ViewPager2 swipe only once on a single swipe

I want to have ViewPager stop capturing swipe events that are outside of the ViewPager container so that the user can never scroll by more than one page during a single swipe like TikTok. If you swipe Tiktok video without release touch(take two…
Tushar Lathiya
  • 940
  • 9
  • 26
0
votes
1 answer

ViewPager2 how to get data from displayed object

I'm having an issue updating the correct student object in my database from viewpager2. My viewpager2 has the ability to display the students alphabetical or by grade, the students don't display in the same order they are in the database. I tried…
Shawn
  • 1,222
  • 1
  • 18
  • 41
0
votes
1 answer

ViewPager2 setCurrentItem method throws error

I'm using a ViewPager2, and I have a button that changes the current page of it to the second page, like this: button_next.setOnClickListener { setup_view_pager.currentItem = 1 } It works until a page is swiped by hand and after that it…
0
votes
1 answer

Calling on bind for the next view in ViewPager2

I'm trying to use new google's ViewPager2 (https://developer.android.com/jetpack/androidx/releases/viewpager2) class that is implemented using RecyclerView. One of the main ideas of ViewPager is that it create "neighbor" views for the selected one…
A. Kazarovets
  • 1,607
  • 1
  • 12
  • 10
-1
votes
1 answer

ViewPager2 Error Fragment Manager is already executing

I am trying to fix a bug where my app crashes if a user performs an orientation change during the onboarding process (I used a 3 fragment viewpager2 layout within JetPack NavHost). I tried adding my viewmodel to it so that it would be lifecycle…
-1
votes
1 answer

Android Viewpager2 and RecyclerView Item onClick listener

I have implemented Viewpager2 Image slider using the code idea mentioned in the following link. I want handle clicks on the slider images. How to Open another activity if the specific slider item clicked. Here is the link of…
-1
votes
1 answer

Navigation component - back button exits the app

I have an issue with back button presses always exiting the app. This is a single activity app where the initial loaded screen is a two tab viewpager2 layout with 2 seperate nav graphs, one for each tab. The viewpager calls two "blank" fragments…
tommytucker7182
  • 213
  • 1
  • 5
  • 11
-1
votes
1 answer

is it possible to change the default direction of a ViewPager Android?

It is possible to override the action of switching screens of a ViewPager that by default drags to the sides (from left to right and vice versa) to pass the screen with movements from top to bottom and from bottom to top?
-1
votes
1 answer

How can I solve this String and int problem?

You see I have a problem: Is there any possibility to somehow change that path to int without changing the code entirely? Im using android studio and currently developing app but Im strugling with one thing. I have a String path of image which needs…
-1
votes
1 answer

Can I change ViewPager's swipe direction from LTR to RTL?

I want to know if I can change swiping direction of ViewPager from LTR to RTL. Please help me.
1 2 3
49
50