翻转效果不会出现在swiperefreshlayout内的recyclerview中

时间:2017-08-28 21:47:04

标签: android android-recyclerview overscroll

我有一个片段,其中包含一个带有RecyclerView的SwipeRefreshLayour。

此recyclerView不显示过度滚动效果。我尝试过很多东西,比如使用它:

 android:isScrollContainer="true"
 android:overScrollMode="always"

通过样式自定义颜色不起作用

fadingEdge,fadingEdgeLengh,requiresFadingEdge ...

滑动以刷新工作正常,显示:

enter image description here

我不明白:

enter image description here

2 个答案:

答案 0 :(得分:0)

在我的这个功能的实现中,(过度滚动在顶部和底部都有效),我有这样的布局:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<...<custom view>...SwipeRefreshWrapper
    android:id="@+id/swiperefresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RecyclerView
            android:id="@+id/video_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <include layout="@layout/include_video_list_empty_view"/>
        <include layout="@layout/include_watchlist_empty_view"/>

    </FrameLayout>
<SwipeRefreshWrapper>

我的SwipeRefreshWrapper实现如下:

/**
* This Class ensures that a SwipeRefreshLayout will only refresh if the
* list it wraps cannot scroll up anymore, (that it is at the top). Otherwise
* when the user attempts to scroll up from the middle of the list, the refresh
* will trigger. This is necessary for custom List implementations, (or
* RecyclerViews), only.
*/
public class SwipeRefreshWrapper extends SwipeRefreshLayout {
     private ScrollResolver mScrollResolver;

     public SwipeRefreshWrapper(Context context) {
         super(context);
     }

     public SwipeRefreshWrapper(Context context, AttributeSet attrs) {
         super(context, attrs);
     }

     public void setScrollResolver(ScrollResolver scrollResolver) {
         mScrollResolver = scrollResolver;
     }

     @Override
     public boolean canChildScrollUp() {
         if(mScrollResolver != null){
             return mScrollResolver.canScrollUp();
         } else {
             return super.canChildScrollUp();
         }
     }

     public static interface ScrollResolver{
         public boolean canScrollUp();
     }
}

然后在我的片段中,我设置了SwipeRefreshLayout:

 /**
 * Initializes PullToRefresh handler
 */
private void initPullToRefresh() {
    mSwipeRefreshLayout = (SwipeRefreshWrapper) mView.findViewById(R.id.swiperefresh_layout);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);

    mSwipeRefreshLayout.setScrollResolver(new SwipeRefreshWrapper.ScrollResolver() {
        @Override
        public boolean canScrollUp() {
            return mVideoRecycler.canScrollVertically(-1);
        }
    });

    mSwipeRefreshLayout.setOnRefreshListener(...)
}

答案 1 :(得分:0)

我只是通过覆盖SwipeRefreshLayout并使用它代替默认实现来解决它:

@extends('voyager::master')
@section('page_title', 'ACD Status')
@section('page_header')
<h1 class="page-title">
    <i class="voyager-phone"></i>
    ACD Status
</h1>
@stop
@section('content')
<div class="page-content edit-add container-fluid" id=>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-bordered">
                <div id="tables">
                    <div id="reload">
                        --Data Here--
                    </div>  
                </div>
                <script language="javascript" type="text/javascript">
                    var timeout = setTimeout(reloadStatus, 5000);
                    var i=0;
                    function reloadStatus(){
                        $('#tables').load('/admin/acd-status #reload',function(){
                            $(this).unwrap();
                            timeout = setTimeout(reloadStatus, 5000);
                        });
                        console.log(i++);
                    }
                </script>
            </div>
        </div>
    </div>
</div>
@stop

我正在使用一个RecyclerView,它是一个线性垂直列表,import android.content.Context import android.util.AttributeSet import android.view.View import androidx.swiperefreshlayout.widget.SwipeRefreshLayout class SwipeRefreshLayoutWithRecyclerViewOverscroll : SwipeRefreshLayout { constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean = (child.canScrollVertically(1) && super.onStartNestedScroll(child, target, nestedScrollAxes)) } 检查该列表当前是否位于最底部。如果它在列表的底部,则onStartNestedScroll返回false,从而允许RecyclerView处理用户的上拉动作,从而显示过度滚动效果。

注意:这仅显示底部边缘过度滚动,而不显示顶部边缘过度滚动,因为我不想与顶部过度滚动边缘一起看到“拉动刷新”动画。