Fragment解析

来源:互联网 发布:淘宝福利群真的假的 编辑:程序博客网 时间:2024/05/18 02:16

fragment在Android3.0以后引入

目的:解决屏幕尺寸的差距

1、fragment的生命周期
①依存Activity存在,生命周期与所在Activity相关

fragment的生命周期

方法意义
onAttach(Activity);  //当Activity与Fragment发生关联时调用

onCreateView(LayoutInflater,ViewGroup,Bundle);  //创建该Fragment的视图

onActivityCreate(bundle);  //当Activity的onCreate();方法返回时调用

onDestoryView();  //与onCreateView相对应,当改Fragment被移除时调用

onDetach();  //与onAttach()相对应,当Fragment与Activity的关联被取消时调用

②静态fragment
1、继承Fragment,重写onCreateView决定Fragemnt的布局

2、在Activity中声明此Fragment,就当和普通的View一样

0 0