当前位置:网站首页>fragment可见性判断
fragment可见性判断
2022-08-05 01:50:00 【TomCat。。。】
1.fragment在activity中之间使用:
这种情况是最简单的,因为此时的fragment的生命周期是和activity的生命周期一致的,当打开另外一个activity的时候,只要监听Fragment的onResume和onPause方法就能够判断其显隐(至于这两个方法什么意思就不多说了,不懂的自己去看activity和fragment的生命周期)
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}2.在ViewPager中的Fragment
ViewPager中Fragment左右切换时,是不会调用onResume()和onPause()方法的。因为这两个方法是跟随activity的生命周期来走的,这个时候我们就可以在fragment中重新 setUserVisibleHint(boolean isVisibleToUser)方法来监听Fragment是否可见
@Override
public voidsetUserVisibleHint(booleanisVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser){
//可见
}else{
//不可见
}
}3.使用show()和hide()方法来显示隐藏fragment
这种情况是在一个activity中fragment切换成另外一个fragment,那么上面两种监听你会发现都没卵用,此时我们可以监听onHiddenChanged(boolean hidden)方法来判断是否对用户可见。
@Override
public void onHiddenChanged(booleanhidden) {
super.onHiddenChanged(hidden);
if(hidden){
//不可见
}else{
//可见
}
}边栏推荐
- Are testing jobs so hard to find?I am 32 this year and I have been unemployed for 2 months. What should an older test engineer do next to support his family?
- 张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
- [Machine Learning] 21-day Challenge Study Notes (2)
- JZ搜索引擎solr研究-从数据库创建索引
- ORA-01105 ORA-03175
- Method Overriding and Object Class
- C# const readonly static 关键字区别
- SAP ERP和ORACLE ERP的区别是哪些?
- Methods commonly used interface automation test framework postman tests
- 如何创建rpm包
猜你喜欢

Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec

自定义线程池

迁移学习——Distant Domain Transfer Learning

张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密

LiveVideoStackCon 2022 Shanghai Station opens tomorrow!

硬实力和软实力,哪个对测试人来说更重要?

pytorch的使用:使用神经网络进行气温预测

A new technical director, who calls DDD a senior, is convinced
![[Endnote] Word inserts a custom form of Endnote document format](/img/70/e8a6f15b80e9c53db369fd715e51df.png)
[Endnote] Word inserts a custom form of Endnote document format

【机器学习】21天挑战赛学习笔记(二)
随机推荐
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
ExcelPatternTool: Excel table-database mutual import tool
JVM类加载简介
2022杭电多校第一场
接口自动化测试框架postman tests常用方法
[Unity Entry Plan] Handling of Occlusion Problems in 2D Games & Pseudo Perspective
【Redis】Linux下Redis安装
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
工具类总结
2021年11月网络规划设计师上午题知识点(上)
缺陷检测(图像处理部分)
MySQL3
ORA-00604 ORA-02429
《.NET物联网从零开始》系列
迁移学习——Distant Domain Transfer Learning
Transfer Learning - Distant Domain Transfer Learning
MySQL3
如何发现一个有价值的 GameFi?
一文看懂推荐系统:召回06:双塔模型——模型结构、训练方法,召回模型是后期融合特征,排序模型是前期融合特征
GCC: compile-time library path and runtime library path