android学习日记之fragment

所有文档及实例均为老师编写归纳,版权均归我的Android老师所有,如有侵权即删

Fragement:

1.      fragment和activity生命周期的对应关系:

06-2710:28:17.684: D/yuanbin(2316): ---MainActivity---onCreate---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onInflate---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onAttach---

06-27 10:28:17.692:D/yuanbin(2316): ---OneFragment---onCreate---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onCreateView---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onViewCreated---

06-2710:28:17.692: D/yuanbin(2316): ---MainActivity---onStart---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onActivityCreated---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onStart---

06-2710:28:17.692: D/yuanbin(2316): ---MainActivity---onResume---

06-2710:28:17.692: D/yuanbin(2316): ---OneFragment---onResume---

06-2710:28:19.744: D/yuanbin(2316): ---MainActivity---onPause---

06-2710:28:19.744: D/yuanbin(2316): ---OneFragment---onPause---

06-2710:28:20.260: D/yuanbin(2316): ---MainActivity---onStop---

06-2710:28:20.260: D/yuanbin(2316): ---OneFragment---onStop---

06-2710:28:20.260: D/yuanbin(2316): ---MainActivity---onDestroy---

06-2710:28:20.260: D/yuanbin(2316): ---OneFragment---onDestroyView---

06-2710:28:20.260: D/yuanbin(2316): ---OneFragment---onDestroy---

06-2710:28:20.260: D/yuanbin(2316): ---OneFragment---onDetach---

2.      fragment替换显示:

fragmentManager.beginTransaction()

.replace(R.id.fragment_frame,twoFragment).commit();

Ps:R.id.fragment_frame必须指定为FrameLayout。

3.      创建Fragment:

创建Fragment时必须重写onCreateView方法,方法return Fragment中显示的视图(View)。


你可能感兴趣的:(技巧)