我的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>正如我所说的,适配器确实会刷新,但是swipeRefreshLayout的动画被卡住了。
我添加了Thread.sleep(4000),只是为了看看它是否能并行运行,但是它所做的只是等到任务完成,也就是4秒,然后停止.
你们有什么想法吗?谢谢你
发布于 2018-10-26 07:21:23
这可能是“滚动冲突”问题,请检查父视图中的onInterceptTouchEvent()和dispatchTouchEvent()。
SwipeRefreshLayout卡住了,这是因为您的swipeRefreshLayout无法获得touchEvent,或者他们将触摸事件分派给子视图,这就是为什么它会卡住。
这可能会有帮助,请检查这个:Android开发人员-管理ViewGroup中的触摸事件
https://stackoverflow.com/questions/36062921
复制相似问题