android - SwipeRefreshLayout 在 API 4.2.2 上卡住

标签 android freeze swiperefreshlayout

在使用 API 21 及更高版本的 Nexus 5 上一切正常,但在使用 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'

这个问题在我的几个 Activity 中都会发生,但作为一个例子,我只是像这样实例化 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

最佳答案

我认为问题的发生是由于 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'

关于android - SwipeRefreshLayout 在 API 4.2.2 上卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33032036/

相关文章:

c# - 使用异步在线程中休眠而不卡住

java - fragment 中的 onRefresh swiperefreshlayout 调用我的主要 Activity 类方法来替换我的 fragment

java - 转换异常 : Multiple dex files define Lcom/google/android/gms/internal/zzcaw;

android - 使用用于 Spinner 的 BaseAdapter

android - recyclerview 中错误的项目更改

angular - Karma 在开始测试之前不会等待构建完成

java - 将 JSONArray 转换为字符串数组

Android Studio 在启动时卡住

Android:CoordinatorLayout 和 SwipeRefreshLayout

android - onPause();对于 SwipeRefreshLayout 不起作用