API 4.2.2上的SwipeRefreshLayout冻结

时间:2015-10-09 07:08:58

标签: android freeze swiperefreshlayout

在我的Nexus 5上使用API​​ 21及更高版本,一切正常,但在使用API​​ 4.2.2的旧版三星设备上,我在SwipeRefreshLayout中遇到以下错误。

任何有类似情况的人?

enter image description here

当我下拉刷新刷新冻结时,直到我开始向上滚动。

这是一个非常不受欢迎的问题,但它是否会与新支持库更新中出现的问题有关?我目前正在使用以下支持库:

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:palette-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

这个问题在我的几个活动中发生,但作为一个例子,我简单地实例化SwipeRefreshLayout,这没有什么不寻常之处。它位于Fragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:orientation="vertical">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeToRefresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

我像这样初始化SwipeRefreshLayout

private void initSwipeRefreshLayout() {
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mSwipeRefreshLayout.setRefreshing(true);
            refreshContent();
        }
    });

    mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
}

private void initRecyclerViewScrollListener() {
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            visibleItemCount = mRecyclerView.getChildCount();
            totalItemCount = mLayoutManager.getItemCount();
            firstVisibleItem = mLayoutManager.findFirstCompletelyVisibleItemPosition();
            lastVisibleItem = mLayoutManager.findLastCompletelyVisibleItemPosition();

            int pageMultiplier = page * PER_PAGE;

            if (!loading) {
                if ((pageMultiplier == totalItemCount) && (lastVisibleItem == pageMultiplier - 1)) {
                    loading = true;
                    page += 1;
                    mPresenter.loadMoreStuff(mStuff.getId(), page, PER_PAGE);
                    mSwipeRefreshLayout.setRefreshing(true);
                }
            }
        }
    });
}

编辑:如果这是相关的,这些问题都发生在Fragments

1 个答案:

答案 0 :(得分:2)

我认为问题是由于v23中SwipeRefreshLayout与v22相比发生了变化,RecyclerView也是如此。切换到v23.0.1后,一切正常。

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:palette-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'