【问题标题】:SwipeRefreshLayout StuckSwipeRefreshLayout 卡住了
【发布时间】:2016-03-17 14:05:33
【问题描述】:

我的 SwipeRefreshLayout 有点问题, 基本上它确实刷新了页面,但是动画卡住了。

刷新时我调用了其他类的 Asynctask,所以我想那里有问题。

我的 SwipeRefresh 监听器:

swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            MyClassAdapter.updateChallenges();
            MyClassAdapter.notifyDataSetInvalidated();
            swipeRefresh.setRefreshing(false);
        }
    });

我的异步任务:

protected MyClass[] doInBackground(String... param) {
    URL oracle;
    BufferedReader in;
    String inputLine;
    String jsonFile = "";

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    try {
        oracle = new URL("someURL");
        in = new BufferedReader(
                new InputStreamReader(oracle.openStream()));
        while ((inputLine = in.readLine()) != null) {
            jsonFile += inputLine;
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return jsonToStructure(jsonFile);
}

XML:

<android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/swipe_to_refresh"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/list_view"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true" />

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

正如我所说,Adapter确实刷新了,但是swipeRefreshLayout的动画卡住了。

P.S : 我添加了 Thread.sleep(4000) 只是为了看看它是否可以并行运行, 然而它所做的只是等到任务完成,也就是 4 秒,然后就走了……

你们有什么想法吗? 谢谢你

【问题讨论】:

  • 你的意思是整个动画卡住了?你能提供更多细节吗?拉动动画有什么问题吗?
  • 嗯,它基本上是这样的:我向下滑动我的页面,看到页面顶部的加载圈,它没有动画(不旋转),工作完成,它消失了(因为"swipeRefresh.setRefreshing(false);")
  • 您也可以显示您的 xml 布局吗?看来您在 swipetorefresh 中没有任何可滚动的视图
  • 添加了,只有滚动视图可以滑动刷新?

标签: android swiperefreshlayout


【解决方案1】:

这可能是“滚动冲突”问题,请检查父视图中的 onInterceptTouchEvent()dispatchTouchEvent()

SwipeRefreshLayout 卡住,这是因为您的 swipeRefreshLayout 无法获取 touchEvent,或者他们将触摸事件分派给子视图,这就是卡住的原因。

这可能会有所帮助,请检查:Android Developer - Manage touch events in a ViewGroup

【讨论】:

    猜你喜欢
    • 2015-08-27
    • 2012-06-23
    • 2021-10-08
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多