Fragment 中使用 SwipeRefreshLayout 导致的不能退出问题
2017-07-04 01:10
246 查看
之前做项目的时候,发现在 Fragment 中使用 SwipeRefreshLayout 会有一个问题,就是当 SwipeRefreshLayout 正在刷新的时候如果切换 Fragment ,会导致当前 Fragment 的界面保留在 Activity 中的相应位置上,切换到其他的 Fragment 会和之前的 Fragment 重合,并且 SwipeRefreshLayout 会一直处于刷新状态直到退出 Activity ,解决方法有两个,下面分别说明。
方法一是在退出 Fragment 的时候结束 SwipeRefreshLayout 动画,并且清除缓存,如下所示:
@Override
public void onDestroyView() {
super.onDestroyView();
refreshLayout.setRefreshing(false);
refreshLayout.destroyDrawingCache();
refreshLayout.clearAnimation();
unbinder.unbind();
}
方法二更简单,在 SwipeRefreshLayout 的外层嵌套一层 FrameLayout ,即保证 SwipeRefreshLayout 不是处在根布局即可:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/tweet_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_300" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
参考自:
https://stackoverflow.com/questions/27057449/when-switch-fragment-with-swiperefreshlayout-during-refreshing-fragment-freezes
方法一是在退出 Fragment 的时候结束 SwipeRefreshLayout 动画,并且清除缓存,如下所示:
@Override
public void onDestroyView() {
super.onDestroyView();
refreshLayout.setRefreshing(false);
refreshLayout.destroyDrawingCache();
refreshLayout.clearAnimation();
unbinder.unbind();
}
方法二更简单,在 SwipeRefreshLayout 的外层嵌套一层 FrameLayout ,即保证 SwipeRefreshLayout 不是处在根布局即可:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/tweet_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_300" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
参考自:
https://stackoverflow.com/questions/27057449/when-switch-fragment-with-swiperefreshlayout-during-refreshing-fragment-freezes
相关文章推荐
- SVN 导致 Eclipse 失败退出,并且不能再启动的问题
- 使用NSKeyedArchiver保存数据导致程序退出问题
- Android系统wifi之p2p(wifi直连)配置文件权限导致应用不能使用wifi问题
- 在Fragment中使用TabLayout,TabLayout不能正常显示的问题。
- 使用sem_t导致不能用gdb调试及线程非正常终止后message queue异常的问题
- delphi 使用工控机控件 iThreadTimes 出现问题, 导致主程序创建页面的时候, 阻塞消息, 不能正常执行。
- Mac os下换行符导致发布到npm里的命令行模块不能使用问题
- 关于GDI资源使用后未释放,导致GDI对象猛增,程序花屏,异常退出的问题
- 解决用PHP连接狗日的SQLSERVER不能使用UTF8,导致乱码的问题
- 同时安装ASA10以及ASA11两个数据库导致不能使用SQLSERVER2005 management studio的问题解决
- java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误
- QQ2013导致adb不能使用问题的修复
- 误删除系统libselinux.SO.1,导致系统命令基本上都不能使用--附解决问题的整个过程
- 关于使用ISA代理导致一些网上银行出现不能正常打开的问题
- Android中application 全局变量 && 使用TAB页不能退出的问题
- 关于使用ISA代理导致一些网上银行出现不能正常打开的问题
- QQ2013导致adb不能使用问题的修复
- WPF直接用Window.Close直接关闭窗口导致不能完全退出的问题
- java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误
- 数据库的使用过程中由于程序方面的问题有时候会碰到重复数据,重复数据导致了数据库部分设置不能正确设置……