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

How to expand the view while zooming an image into ViewPager2

I was trying, with ViewPager2, to get default gallery-like experience of common Android SmartPhone, where you can zoom an image with pan and pinch controls along with the ability to navigate to another photo by swipe gestures. I faced a problem in…
Robert88
  • 1
  • 3
0
votes
1 answer

Soft input keyboard moves my static bottom view up Android Kotlin

I have a Fragment with a static top view,a static bottom view and a ViewPager2 in the middle of those 2 views.(Look for Picture1 in the link provided). I have a problem when the keyboard shows up my bottom static view moves up. I tried all of…
0
votes
2 answers

Update multiple fragments with same layout after doing Async Task in TabLayout and ViewPager2

I'm using TabLayout and ViewPager2 in order to show up to 3 fragments with same layout. A fragment per tab. All 3 fragments should update his own ListView after an Async Task is completed. All fragments share the same layout but each fragment has…
0
votes
0 answers

Best practice using ViewPager2 with RecyclerView in it and using Navigvation Component for onItemClick of RecyclerView

i am working with single activity and MVVM artitechture its have main activity for just launcher then there is the MainFragment from there we go to ViewPagerContainerFragment using navigation component and in that fragment i have viewpager2 setup…
0
votes
1 answer

Image & Video slider using Viewpager2 , some videos appeared missing in sliding

I am working in a image and video slider. I can load my images and videos in a viewpager 2. but now, images are working correct, but during sliding video will only be appeared sometimes..otherwise next image takes its place..what is wrong ?…
0
votes
1 answer

android kotlin what is the current way of make sure viewPager2 pageItem resume is fired only when onscreen?

I want init tasks (starting a countDownTimer) only when the viewPager2 pages become visible. and stop timer when they get off-screen. however, I got stuck on the fact that resume() is fired when off-screen for pageItem. setUserVisibleHint seems…
0
votes
2 answers

Sliding between fragments using Viewpager2 and Kotlin

I have an old project written in Java made to slide horizontally between three different fragments, and they were stated on the main activity. It worked perfect. public class MainActivity extends AppCompatActivity { ViewPager pager; @Override …
0
votes
0 answers

appBar still taking space while visibility is gone

I used ViewPager2 to implement tablayout but when i try to hide the app Bar in the first tab it still takes its space. Don't know why it takes space while using the code below but if i simply use appBar.visibility = View.GONE outside this…
Mohit Kumar
  • 552
  • 9
  • 29
0
votes
1 answer

Imageview automatically adjusts Images that are loaded into it

I am using glide to load images into an imageview that uses viewpager2 to slide through images.When I load an image to the imageview it first fills the width of the screen then it increases in width again like it's imitating a zooming behaviour. My…
0
votes
1 answer

ViewPager2 must not be null in NavigationDrawer and SwipeViewTabs

I am trying to link my Navigation Drawer with SwipeView Tabs, the problem is that the logcat tells me that my Viewpager must not be null, I have tried to solve this problem in many ways but could not. PageAdaper.kt class…
0
votes
0 answers

Type mismatch: inferred type is FragmentManager but FragmentActivity was expected

So I'm having an issue in Kotlin when migrating from viewpager to viewpager2. Below is both the old working code, and the new attempt at migrating to viewpager2, as well as the error message I get when running the new code. Old working…
0
votes
0 answers

ViewPager2: Listen for setCurrentItem() completion

I recently upgraded my app to use ViewPager2. When the user taps the finish-early button I call this code. setCurrentItem(myLastPageIndex, false) doSomeWork() The doSomeWork() function enables the circular progress bar on the last page. The thing…
Tiago Oliveira
  • 1,582
  • 1
  • 16
  • 31
0
votes
0 answers

How to implement video playback using VideoView inside nested ViewPager2?

My intention is to implement nested ViewPager using ViewPager2. Each page of the horizontal-scroll ViewPager contains a vertical-scroll ViewPager which contains a list of videos by a category. Video auto-play when the page visible to the user and…
0
votes
0 answers

Swipe ViewPager2 fragment from DrawerLayout Activity Programmatically

Hi everyone, I have a Activity with a DrawerLayout -> Inside a FrameLayout for change view (Fragment) My ViewPagerFragment have TabAdapter with 2 Fragment and TabLayout I have a ViewPagerFragment with currentItem at 0 and another ViewPagerFragment2…
0
votes
1 answer

ViewPager2 not updating fragment with POSITION_NONE

I have implemented ViewPager2 and implemented with 2 tabs. I want to refresh each fragment between consecutive swipe with the following code but it is not working. @Override public int getItemCount() { return POSITION_NONE; } It throws…
Bishwash
  • 854
  • 1
  • 9
  • 22