按照官网的例子的修改而成


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、自己



更多相关文章

  1. RelativeLayout(Android)中实现控件平分屏幕
  2. android TextView EditTextView一些技巧使用 (视图代码布局)
  3. Android热补丁动态修复技术(二):实战!CLASS_ISPREVERIFIED问题!
  4. Android(安卓)OutOfMemory 的思考
  5. [置顶] android 实现发送彩信方法 (MMS),非调用系统彩信界面
  6. Android设置透明状态栏,仿ios状态栏
  7. Android中TextSwitcher的功能与用法
  8. 【安卓项目】—— 口算测试APP(教程源自B站)
  9. 反射技术在android中的应用

随机推荐

  1. android dpi换算以及常用分辨率列表
  2. Android邮件地址正则表达式
  3. Android之水平ProgressBar多彩背景颜色
  4. android 获取农历日期和天干、地支
  5. Android显示网络图片相关实现方法浅谈
  6. Android(安卓)O 去掉Launcher3 背景阴影
  7. Android开场透明度渐变动画
  8. android 网络判断
  9. Android(安卓)屏幕滑动事件
  10. 卸载android应用程序