android-viewpager2

ViewPager2 with Tablayout inside a fragment shows no swipe effect in kotlin

99封情书 提交于 2020-07-22 05:13:47
问题 In my MainActivity I have a viewpager2 with Tablayout with 5 tabs. The swipe there is working fine. But in one of the 5 tabs I again have a viewpager2 with a tablayout of 3 tabs. In the inner viewpager2 (which is inside a fragment) the swipe isnt working at all and I don't understand why. The outer viewpager2 is inside a activity while the inner viewpager2 is in the fragment Viewpager2 inside fragment , swipe not working : class FreelancerMyProjectsFragment : Fragment() { lateinit var binding

ViewPager2 not able to dynamically add remove fragment

怎甘沉沦 提交于 2020-07-19 10:58:26
问题 Removing/Adding fragments at index results in unexpected behaviour in Viewpager2. This was not possible with ViewPager but expected to work with Viewpager2 . It causes duplicate fragments and out of sync TabLayout . Here is a demo project which reproduces this issue. There is a toggle button which removes a fragment and reattaches it at a particular index. In this case attached fragment should be green but it's blue and there are 2 blue fragments somehow. here is how my adapter looks class

Fragments in ViewPager2 does not respond to clicks if scroll position is 0

筅森魡賤 提交于 2020-07-19 05:25:12
问题 I am very glad that Google released ViewPager2 which is built on RecyclerView to solve a lot of issues that the old ViewPager has. I quickly replaced my old ViewPager codes to ViewPager2: Replace ViewPager with ViewPager2 in xml Replace FragmentPagerAdapter(FragmentManager) with FragmentStateAdapter(Fragment) ViewPager setup is as below: viewPager.adapter = fragmentAdapter val mediator = TabLayoutMediator(tabLayout, viewPager, true) { tab, position -> tab.text = fragmentAdapter.tabNames

Scrolling behaviour conflicts with a child RecyclerView and a parent Viewpager2

六眼飞鱼酱① 提交于 2020-06-27 12:54:05
问题 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 RecyclerView . The only way to make the scroll inside the RecyclerView is if I scroll really slow, if I make it fast, like a swipe event the ViewPager2 gets scrolled and changes the page. Currently I'm doing a fix that involves disabled the user

Android ViewPager2 setPageMargin unresolved

百般思念 提交于 2020-06-24 07:43:33
问题 I want to implement Carousel using View Pager2 with preview of left and right page like this: Initially I was using view pager1 which supported. Now I think it's removed viewPagerhost.setPageMargin(20); Any idea how we can achieve this using View Pager 2 回答1: Now we need to use setPageTransformer() in Version 1.0.0-alpha05 New features ItemDecorator introduced with a behaviour consistent with RecyclerView. MarginPageTransformer introduced to provide an ability to create space between pages

Android ViewPager2 setPageMargin unresolved

僤鯓⒐⒋嵵緔 提交于 2020-06-24 07:43:11
问题 I want to implement Carousel using View Pager2 with preview of left and right page like this: Initially I was using view pager1 which supported. Now I think it's removed viewPagerhost.setPageMargin(20); Any idea how we can achieve this using View Pager 2 回答1: Now we need to use setPageTransformer() in Version 1.0.0-alpha05 New features ItemDecorator introduced with a behaviour consistent with RecyclerView. MarginPageTransformer introduced to provide an ability to create space between pages

How to create a custom view extending from viewpager2?

∥☆過路亽.° 提交于 2020-06-23 11:42:24
问题 I would like to create my own version of custom ViewPager2 view from extending from the original Viewpager2, but just had a hard time doing it. I get errors such as Cannot inherit from final 'androidx.viewpager2.widget.ViewPager2' Is there a better way to extend from a Viewpager2 so that I could add cusotm functionality? 回答1: If you want to extend it just because you need Not-Swipeable behaviour, you dont need to do it. ViewPager2 provides nice property called : isUserInputEnabled 回答2: It's

How to disable swiping in specific direction in ViewPager2

假如想象 提交于 2020-06-23 09:58:33
问题 I want to disable right to left swipe in ViewPager2 . I basically have a viewpager2 element with 2 pages in my navigation drawer. I want my second page to show up only when I click some element in my first page (right to left swipe from the first page should not open the second page), while when I'm in the second page, the viewpager2 swipe (left to right swipe) should swipe as it should do in viewpager. I've tried extending the ViewPager2 class and override the touch events, but unfortunately

Page(s) contain a ViewGroup with a LayoutTransition (or animateLayoutChanges=“true”), which interferes with the scrolling animation

醉酒当歌 提交于 2020-05-13 07:35:55
问题 I use fragments with ViewPager2, and I notice two relevant IllegalStateExceptions in production (I can't reproduce it myself) occurring in devices like Xiaomi, Yulong, asus, vivo running Android 8 or 9: Fatal Exception: java.lang.IllegalStateException: Page can only be offset by a positive amount, not by -758 at androidx.viewpager2.widget.ScrollEventAdapter.updateScrollEventValues(ScrollEventAdapter.java:280) at androidx.viewpager2.widget.ScrollEventAdapter.onScrolled(ScrollEventAdapter.java

How to disable swiping in ViewPager2?

不问归期 提交于 2020-05-08 06:06:26
问题 Is it possible to enable-disable swiping in new android viewpager2 component? 回答1: Now it is possible to enable-disable swiping viewpager2 using Version 1.0.0-alpha02 Use implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha02' Version 1.0.0-alpha02 New features Ability to disable user input ( setUserInputEnabled , isUserInputEnabled ) API changes ViewPager2 class final Bug fixes FragmentStateAdapter stability fixes SAMPLE CODE to disable swiping in viewpager2 myViewPager2