- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
5.2.5 Fragment实例精讲——新闻(购物)类App列表Fragment 的简
单实现
本节引⾔:
相信⼤家对点击列表,然后进⼊详情这种App并不陌⽣吧,在购物类App
和新闻类App 中 为常见: 下⾯我们简单来讲⼀下流程逻辑 !
1.逻辑流程讲解:
刚好公司测试妹⼦的测试机上装了楚楚街9块9的APP ,呵呵,直接就照这个来研究
吧:
嘿嘿,市⾯上很多APP都是这种样⼦的,⽽这个可以⽤我们学到的Fragment来实现:
可能gif动画看不清,笔者⽤界⾯原型⼯具画个⼤概吧:
⼤概就这样,中间区域是⼀个布局容器,⼀般是FrameLayout ,然后我们将⼀个
Fragment replace 到这个容器中或者add也⾏,⽽这个Fragment 中有⼀个listview ,当我
们点击这个ListView 中的⼀项, 中间容器中的Fragment就会被replace成对应详细信息
的Fragment所替代,如果我们只是replace的话, 就不会保存第⼀个Fragment的状态,
⽤户又得从头开始浏览,这肯定是很不⽅便的,这⾥我们可以 通过Fragment栈的
addtobackStack和popbackstack来解决这个问题 !当replace的同时,我们将被替换 的
Fragment添加到stack 中,当⽤户点击回退按钮时,调⽤popbackstack弹出栈,具体实现
见下述代码 ⽰例 !
2.代码⽰例:简单新闻类APP列表和内容 换的实现
运⾏效果图:
实现代码:
Step 1:先把两个Fragment 以及Activity的布局实现了
fg_newlist.xml:
?xml version=1.0 encoding=utf-8?
LinearLayout xmlns:android= ttp://sc /apk/res/an
android:layout_widt =matc _parent
android:layout_ eig t=matc _parent
android:background=@color/w ite
android:orientation= orizontal
ListView
android:id=@+id/list_news
android:layout_widt =matc _parent
android:layout_ eig t=matc _parent /
/LinearLayout
fg_context.xml:
?xml version=1.0 encoding=utf-8?
LinearLayout xmlns:android= ttp://sc /apk/res/an
android:layout_widt =matc _parent
android:layout_ eig t=matc _parent
android:orientation=vertical
TextView
android:id=@+id/txt_content
android:layout_widt =matc _parent
android:layout_ eig t=matc _parent
android:gravity=center
android:textColor=@color/blue
android:textSize=20sp /
/LinearLayout
activity_main.xml:
RelativeLayout xmlns:android= ttp://sc /apk/res/
xmlns:tools= ttp://sc /tools
android:layout_widt =matc _parent
android:layout_ eig t=matc _parent
tools:context=.MainActivity
TextView
android:id=@+id/txt_title
android:layout_widt =matc _parent
android:layout_ eig t=56dp
android:back
原创力文档


文档评论(0)