Fragment 中使用 SwipeRefreshLayout 导致的不能退出问题
来源:互联网 发布:车载导航端口检测工具 编辑:程序博客网 时间:2024/06/02 05:55
之前做项目的时候,发现在 Fragment 中使用 SwipeRefreshLayout 会有一个问题,就是当 SwipeRefreshLayout 正在刷新的时候如果切换 Fragment ,会导致当前 Fragment 的界面保留在 Activity 中的相应位置上,切换到其他的 Fragment 会和之前的 Fragment 重合,并且 SwipeRefreshLayout 会一直处于刷新状态直到退出 Activity ,解决方法有两个,下面分别说明。
方法一是在退出 Fragment 的时候结束 SwipeRefreshLayout 动画,并且清除缓存,如下所示:
@Overridepublic 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
阅读全文
0 0
- Fragment 中使用 SwipeRefreshLayout 导致的不能退出问题
- 项目中异常退出导致的问题。
- SwipeRefreshLayout 使用中遇到的问题
- 关于ViewPager嵌套Fragment,Fragment使用GridView导致的问题
- activity中fragment不能全屏的问题
- Android中application 全局变量 && 使用TAB页不能退出的问题
- Android中SwipeRefreshLayout的使用
- Android中SwipeRefreshLayout的使用
- Android中SwipeRefreshLayout的使用
- Fragment中多次调用onCreatView()导致异常问题的解析
- SVN 导致 Eclipse 失败退出,并且不能再启动的问题
- 解决Three.js中使用OrbitControls导致不能选中DOM的问题
- 关于IDEA中src下不能使用xml文件导致的问题
- 在Fragment中使用TabLayout,TabLayout不能正常显示的问题。
- jquery中关于return不能退出方法的问题
- viewpager+fragment嵌套viewpager图片广告导致广告图片不能滑动的问题用LinearLayout实现
- SwipeRefreshLayout 配合fragment 下拉刷新的使用,超级简单
- policykit-gnome导致unlock不能使用的问题
- Leetcode: 23.Merge k Sorted Lists
- FDES
- 三维重建面试11:点云的全局特征总结
- 实训笔记第六天
- 深入理解Java:注解(Annotation)自定义注解入门
- Fragment 中使用 SwipeRefreshLayout 导致的不能退出问题
- Linux下查找MySQL配置文件和日志文件位置
- 如何实现模拟相机光圈改变的动画
- Excel应用-各地GDP的综合对比图表-Part2(平均线图、复合饼图、瀑布图、帕累托图)
- vector迭代器失效问题
- android studio常见问题汇总
- Vue.js 环境搭建
- 【Leetcode】【python】Two Sum, Two Sum II
- Mac 安装dotnet后,仍然无法执行dotnet