Fragment(二)-----分析执行的过程篇
16lz
2021-01-26
按照官网的例子的修改而成
1、Fragment初始化的流程
主界面调用下面的加载布局的代码后,
setContentView(R.layout.news_articles);//加载布局中的fragment
布局:news_articles.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:name="com.example.android.fragments.HeadlinesFragment" android:id="@+id/headlines_fragment" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" /> <fragment android:name="com.example.android.fragments.ArticleFragment" android:id="@+id/article_fragment" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" /></LinearLayout>
界面就开始加载android:name中声明的类,其执行的流程
详情见图。
2、添加一个Fragment
// Create fragment and give it an argument for the selected articleArticleFragment newFragment = new ArticleFragment();Bundle args = new Bundle();args.putInt(ArticleFragment.ARG_POSITION, position);newFragment.setArguments(args);//添加一些附带的参数进去FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this// fragment,// and add the transaction to the back stack so the user can// navigate backtransaction.replace(R.id.fragment_container, newFragment);transaction.addToBackStack(null);// Commit the transactiontransaction.commit();
详见: http://blog.csdn.net/aomandeshangxiao/article/details/7671533#t8
3、自己
更多相关文章
- RelativeLayout(Android)中实现控件平分屏幕
- android TextView EditTextView一些技巧使用 (视图代码布局)
- Android热补丁动态修复技术(二):实战!CLASS_ISPREVERIFIED问题!
- Android(安卓)OutOfMemory 的思考
- [置顶] android 实现发送彩信方法 (MMS),非调用系统彩信界面
- Android设置透明状态栏,仿ios状态栏
- Android中TextSwitcher的功能与用法
- 【安卓项目】—— 口算测试APP(教程源自B站)
- 反射技术在android中的应用