【问题标题】:Strange glitches when using "Pull to refresh"使用“拉动刷新”时出现奇怪的故障
【发布时间】:2016-04-08 09:39:44
【问题描述】:

当我启动我的活动时,我会刷新我的列表

swipeContainer.setRefreshing(true);

刷新后调用

swipeContainer.setRefreshing(false);

但是在网络调用过程中,刷新图标会在几分之一秒内出现故障

如果我查看 Android 监视器,我会看到这些行

D/OpenGLRenderer: endAllStagingAnimators on 0x7f926f5800 (RippleDrawable) with handle 0x7f8dcf50e0

D/OpenGLRenderer: endAllStagingAnimators on 0x7f7ce78000 (ListView) with handle 0x7f89455380

这是什么意思?以及如何解决这个问题,我没有收到故障和消息?

真的很烦

编辑 1 这就是我调用 setRefreshing(true) 的方式

    swipeContainer.post(new Runnable() {
        @Override
        public void run() {
            swipeContainer.setRefreshing(true);
        }
    });

【问题讨论】:

  • 使用处理程序......
  • 喜欢 EDIT 1?因为这就是我调用 setRefreshing(true); 的方式
  • 为什么不使用 swipeRefresh?我的代码使用 swipeRefresh,如果你愿意,我可以发布。
  • 您是否有可能在 UI 线程上执行繁重的任务?这可能会导致您的应用中的整体 UI 性能下降(即使是一小会儿)
  • 什么是繁重的任务?我所有的网络调用都是在 AsyncTask 中完成的

标签: android listview pull-to-refresh rippledrawable


【解决方案1】:

我使用 swipeRefreshLayout,这可能对你有用:

我的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background2"
android:layout_marginTop="56dp"
android:weightSum="1">

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

    <ListView
        android:id="@+id/lv1"
        android:layout_marginTop="15dp"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:background="#f0f0f0"
        android:alpha="0.90"
        android:layout_weight="1.01" />

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

这是我用来刷新活动的代码:

SwipeRefreshLayout mSwipeRefreshLayout;

mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipelayout);

    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    finish();
                    startActivity(getIntent());
                }
            }
    );

【讨论】:

  • 这正是我所做的,但是当你第一次打开你的活动时,需要从我的服务器调用列表,如果你只使用你的代码,进度条只会在你拉的时候出现下来,我通过调用 setRefreshing(true) 来显示进度条,如果任务完成(在另一个线程中)我调用 setRefreshing(false)
  • @KoenVanLooveren 那么你是说你希望它在从服务器加载数据时刷新?我在技术上做的一切都是一样的,我从 WebAPI 中提取数据,然后用数据填充列表视图,如果我正确理解你的响应,你的意思是你想在创建列表视图时刷新它吗?为什么?如果您正确填充列表视图并正确设置它应该在您看到任何内容之前已经填充。如果我没有完全理解,那么对不起:)
  • 不,这不是真的,我打开我的活动,然后才会从互联网调用数据,因为我只需要那个活动的数据
  • @KoenVanLooveren 所以你首先创建你的视图然后填充列表?抱歉,我不完全了解您的情况。
  • 是的,所以我的视图被创建,然后我得到了我的服务器列表,(通过网络)当你在等待列表时(通过网络),我想向用户显示相同的加载栏如果他下拉刷新列表
猜你喜欢
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 2021-05-30
  • 2018-04-12
  • 1970-01-01
  • 2021-05-16
  • 2012-06-07
  • 1970-01-01
相关资源
最近更新 更多