【发布时间】: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