大叔程序员的第二天 @Fragment学习
2013-03-05 14:39
162 查看
Fragment生命周期类似于Activity。
用于分屏显示功能。
使用可继承Fragment类或者其三个子类:DialogFragment,ListFragment,PreferenceFragment。
文库的学习资料http://wenku.baidu.com/view/13fa98c008a1284ac8504331.html介绍的比较全。
举个2个创建Fragment的例子,下面是一个由2个Fragment组成的Activity
例子是一个有2个fragment的activity: <?xml version="1.0" encoding="utf-8"?>
<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.news.ArticleListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.news.ArticleReaderFragment"
android:id="@+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
而如果想通过无UI的方法调用Fragment,则可通过要添加一个无UI的fragment, 需要从activity使用 add(Fragment, String) 来添加 fragment
(为fragment提供一个唯一的字符串"tag", 而不是一个view ID).这么做添加了fragment, 但因为它没有关联到一个activity layout中的一个view,
所以不会接收到onCreateView()调用. 因此不必实现此方法.
管理Fragment
常用的方法如getFragmentManager(), findFragmentById(),findFragmentByTag()
用于分屏显示功能。
使用可继承Fragment类或者其三个子类:DialogFragment,ListFragment,PreferenceFragment。
文库的学习资料http://wenku.baidu.com/view/13fa98c008a1284ac8504331.html介绍的比较全。
举个2个创建Fragment的例子,下面是一个由2个Fragment组成的Activity
例子是一个有2个fragment的activity: <?xml version="1.0" encoding="utf-8"?>
<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.news.ArticleListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.news.ArticleReaderFragment"
android:id="@+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
而如果想通过无UI的方法调用Fragment,则可通过要添加一个无UI的fragment, 需要从activity使用 add(Fragment, String) 来添加 fragment
(为fragment提供一个唯一的字符串"tag", 而不是一个view ID).这么做添加了fragment, 但因为它没有关联到一个activity layout中的一个view,
所以不会接收到onCreateView()调用. 因此不必实现此方法.
管理Fragment
常用的方法如getFragmentManager(), findFragmentById(),findFragmentByTag()
相关文章推荐
- 大叔程序员的第二天@R文件丢失&滑动事件&项目搜索字符&Intent 2种写法
- 大叔程序员的第二天 @触摸关闭软键盘
- 大叔程序员的第一天 @几个布局时的小问题
- 漫画:什么是 volatile 关键字? 2017-12-21 玻璃猫 Java编程 来自:程序员小灰(微信号:chengxuyuanxiaohui) ————— 第二天 ————
- 大叔程序员的第10天 @内存泄露
- 大叔程序员第15天 @JSON解析
- 当年也是翩翩少年,如今落得秃顶大叔,程序员秃顶算工伤吗?
- 程序员的第二天
- 大叔程序员的第九天 @广播启动Activity
- 20131209这是我成为程序员道路上的第二天
- 程序员学炒股(7) 股指期货收盘价对第二天开盘价有影响吗?
- 小白程序员的第二天
- SegmentFault 巨献 1024 程序员游戏「红岸的呼唤」第二天任务攻略
- 80后程序员大叔辞职带娃,背着相机环游世界!
- 调试大叔V1.0.1(2017.09.01)|http/s接口调试、数据分析程序员辅助开发神器
- 大叔程序员的第九天 @动态添加Layout--用Radio进行切换
- 大叔程序员的第12天 @Image放图片的总结
- 大叔程序员的第六天 @布局&eclipse配置文件
- 看程序员是怎么喝酒的(搞笑)
- 程序员,到了吃芋头的时候了