SwipeRefreshLayout interferes with ScrollView in a ViewPager

前端 未结 3 541
余生分开走
余生分开走 2021-01-05 14:04

I have a SwipeRefreshLayout around a ViewPager. The fragments loaded by the ViewPager contain ScrollViews. When I scroll d

3条回答
  •  一整个雨季
    2021-01-05 14:35

    I solved the problem. I created SwipeRefreshLayout like this:

    public class MenuSwipeRefreshLayout: SwipeRefreshLayout {
    
        public var target: View? = null
    
        constructor(ctx: Context): super(ctx)
        constructor(ctx: Context, attr: AttributeSet): super(ctx, attr)
    
        override fun canChildScrollUp(): Boolean {
            return target?.canScrollVertically(-1) ?: super.canChildScrollUp()
        }
    }
    

    and I set the target to the visible ScrollView every time the ViewPager changes views.

    BTW that's Kotlin, not Java.

提交回复
热议问题