天道酬勤,学无止境

android-viewpager2

Android - Program type already present com.transition.R while importing ViewPager2 library

Gradle is throwing Program type already present: androidx.transition.R" after importing androidx.viewpager2:viewpager2:1.0.0-beta02 implementation 'androidx.viewpager2:viewpager2:1.0.0-beta02' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.vectordrawable:vectordrawable:1.0.1' implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' AGPBI: {"kind":"error","text":"Program type already present: androidx.transition.R","sources":[{}],"tool":"D8"} Expected outcome: Gradle should compile with no error

2021-06-14 07:26:47    分类:问答    androidx   android-viewpager2

Vertical ViewPager2 with RecyclerView Scrolling Issue

I'm using a ViewPager2 with two fragments in a vertical orientation. When the user swipes down to the second fragment, there is a RecyclerView that scrolls content in the same vertical direction. The issue is that when I scroll the contents of the RecyclerView, sometimes the ViewPager2 catches the scroll events and sometimes the RecyclerView catches the scroll events. I would like it so that when the user is scrolling to the top of the RecyclerView, the ViewPager only swipes back up to the first fragment when the user has reached the top of the contents in the RecyclerView. I've tried using

2021-06-05 20:07:20    分类:问答    android-fragments   android-recyclerview   android-nestedscrollview   vertical-scrolling   android-viewpager2

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

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:178) at androidx.recyclerview.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:5173) at

2021-06-05 06:07:11    分类:问答    java   android   android-recyclerview   android-viewpager2

viewpager2 interaction with SwipeRefreshLayout

I have viewpager2 with 4 fragments. 3 of them have SwipeRefreshLayout to refresh async task data in particular fragments. When using SwipeRefreshLayout and viewpager2 the gestures are somehow conflicting. ie. swype down to refresh makes screen so sensitive, that a little move to left or right also makes page screen change and refresh icon is freezing or the processis unfinished. my goal is to make gestures independent, so for example when i start to swype down SwipeRefreshLayout, then vp2 is disabled so it it is not interfere with SRL. This was not happening when using standard viewpager with

2021-06-02 19:56:18    分类:问答    android   swiperefreshlayout   android-viewpager2

ViewPager2 not able to dynamically add remove fragment

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 ViewPager2Adapter(activity: FragmentActivity) : FragmentStateAdapter(activity) { val fragmentList

2021-06-02 15:44:44    分类:问答    android   android-fragments   android-viewpager   android-viewpager2

ViewPager2 | View.ClickListener not called

I use new android widget ViewPager2 version 1.0.0-alpha03 and when I set click listener on it method onClick() not called. My Actvity class: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) supportFragmentManager.beginTransaction() .add(R.id.fragmentContent, SecondFragment.newInstance(), SecondFragment.TAG) .addToBackStack(SecondFragment.TAG) .commit() } } My Fragment: class SecondFragment : Fragment() { companion object { val TAG = SecondFragment::class.java.canonicalName

2021-06-02 01:18:16    分类:问答    android   android-viewpager2

How to wrap height of Android ViewPager2 to height of current item?

This question is for the new ViewPager2 class. There is a similar question for the old ViewPager, but the solution requires extending ViewPager. However, ViewPager2 is final so cannot be extended. In my situation, I have a ViewPager2 that contains three different fragments. One of these fragments is much taller than the other two, which means when you swipe to one of the shorter fragments, there is a lot of empty space. So how do I effectively wrap the ViewPager2 to the height of the current fragment?

2021-06-01 17:19:23    分类:问答    android   android-fragments   android-viewpager   android-viewpager2

Fragment no longer exists for key FragmentStateAdapter with Viewpager2

I am using ViewPager2 for my project. I need to use nested fragments inside a fragment with viewpager2. it works like charm until I try to navigate between fragments(not nested ones). After the first time navigating between fragments, the application crash with the error explained below. the fragment which contains nested fragments OnCreateView method: View view = inflater.inflate(R.layout.orders_fragment, null); ViewPager2 viewPager = view.findViewById(R.id.childViewPager); TabLayout tabs = view.findViewById(R.id.tabs); SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter

2021-05-26 03:13:53    分类:问答    android   android-fragments   android-adapter   fragmentstatepageradapter   android-viewpager2

Android ViewPager2 setPageMargin unresolved

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

2021-05-24 14:53:41    分类:问答    android   carousel   android-viewpager2

remove fragment in viewPager2 use FragmentStateAdapter, but still display

I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3 has been removed, but the displayed page still has fragment3 content. Adpter: class TipsAdapter( private val items: MutableList<TripPage>, context: FragmentActivity ) : FragmentStateAdapter(context) { private val fragmentFactory = context.supportFragmentManager.fragmentFactory private val classLoader = context.classLoader override fun getItemCount()

2021-05-16 07:52:35    分类:问答    android   android-viewpager   fragmentstatepageradapter   android-viewpager2