FragmentTransaction 常用方法总结
来源:互联网 发布:hiphop服装品牌知乎 编辑:程序博客网 时间:2024/05/18 03:52
1)add
1
add(int containerViewId, Fragment fragment, String tag)
把fragment添加到activity指定的容器中
注意: fragment 必须是没有添加过的,获取是否已经添加使用FragmentManager.findFragmentByTag(String)
2)attach
1
attach (Fragment fragment)
把fragment重新添加到当前的 view hierarchy ,并显示,fragment 的onCreateView 会重新执行,布局重新绘制。
注意:fragment必须是经过detach
3)detach
1
detach (Fragment fragment)
从当前的UI中分离fragment,fragment的视图结构会被破坏。
4) hide
1
hide (Fragment fragment)
隐藏fragment,fragment必须是添加过的,只会隐藏当前的fragment。
5)remove
1
remove (Fragment fragment)
如果container存在fragment,从container中移除 fragment。
6)replace
1
replace (int containerViewId, Fragment fragment, String tag)
相当先调用remove (Fragment fragment)
,在调用add(int containerViewId, Fragment fragment, String tag)
7)show
1
show (Fragment fragment)
显示之前hide(fragment)
,同样fragment必须已经是添加过到container中。
fragment几个属性
1)onAttach
和onCreate
123
//fragment第一次attach到当前的activityonAttach(Activity activity)onCreate(Bundle savedInstanceState)
2)onCreateView
12
//创建视图onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
三种fragment使用情况
1)第一种add()
+ attach()
+ detach()
fragment
上述1
执行一次 ,2
会在每次attach()
执行
2)第二种replace()
fragment
上术都会执行
3)第三种add()
+ hide()
+ show()
fragment
上述执行一次
一些理解,如有不对,请留言...
声明:eoe文章著作权属于作者,受法律保护,转载时请务必以超链接形式附带如下信息
原文作者: 花_开_堪_折_枝
原文地址: http://my.eoe.cn/yaming/archive/2500.html
- FragmentTransaction 常用方法总结
- FragmentTransaction 实用方法
- FragmentTransaction add replace remove方法
- FragmentTransaction
- FragmentTransaction
- FragmentTransaction
- FragmentTransaction
- FragmentTransaction的replace()方法和add()方法
- FragmentTransaction add和replace方法的区别
- jquery常用方法总结
- jquery常用方法总结
- luabind常用方法总结
- JQuery常用方法总结
- JQuery常用方法总结
- jquery常用方法总结
- Java常用方法总结
- jQuery 常用方法总结
- jQuery 常用方法总结
- 初学PHP刚写了一个简单计算页面,分享一下
- Linux顶层Makefile分析
- Unity3d webplayer连接Sokcet服务器
- Linux Socket编程(不限Linux)(转)
- 用cygwin工具重新编译cocos2d-x工程的方法
- FragmentTransaction 常用方法总结
- Android系统中setprop,getprop,watchprops命令的使用
- 初探 ndk 之环境搭建
- Sample Shell Script To Loop Through All Files
- [转]addr2line探秘
- delphi opendialog设置默认打开路径
- create_proc_read_entry(), create_proc_entry() | 创建 /proc 文件
- I/O模型学习(一)
- linux网络编程(一)——程序、进程和线程的概念