SwipeRefreshLayout with scrollView and Layout above

后端 未结 4 500
攒了一身酷
攒了一身酷 2020-12-28 13:39

I have the following layout



        
相关标签:
4条回答
  • 2020-12-28 14:07

    Use NestedScrollView with:

         app:layout_behavior="@string/appbar_scrolling_view_behavior"
    
    0 讨论(0)
  • 2020-12-28 14:13

    Make your own implementation of SwipeRefreshLayout and override the canChildScrollUp in this way:

        @Override
    public boolean canChildScrollUp() {
        if (scrollView != null)
            return scrollView.canScrollVertically(-1);
    
        return false;
    }
    

    just replace with any subclass of ScrollView.

    0 讨论(0)
  • 2020-12-28 14:23

    If you have layout like this:

    <SwipeRefreshLayout>
        <android.support.v4.widget.NestedScrollView
            android:id="@+id/your_scroll_view_id">
            <LinearLayout>
            ...
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </SwipeRefreshLayout>
    

    You need to create your own class and override the function in this way:

    class SwipeRefreshLayoutCustom extends SwipeRefreshLayout {
        public SwipeRefreshLayoutCustom(Context context, AttributeSet attributes) {
            super(context, attributes)
        }
        @override
        boolean canChildScrollUp() {
            return your_scroll_view_id.scrollY != 0
        }
    }
    
    0 讨论(0)
  • 2020-12-28 14:31

    I found that if you replace your ScrollView with a android.support.v4.widget.NestedScrollView the scrolling behavior will work as you expect it to.

    0 讨论(0)
提交回复
热议问题