- 1、本文档共10页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
5.2.5 Fragment实例精讲——新闻(购物)类App列表Fragment的简单实现.pdf
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:ba
您可能关注的文档
最近下载
- 四川省红十字应急救护知识竞赛考试题库资料(含答案).pdf
- 新沪教版高中信息技术必修1《解决温标转换问题——认识程序和程序设计语言》说课稿.doc
- 基于功能磁共振成像的脑网络研究.pptx
- 码头水利技术规定条文2010-09.pdf
- 中医院临床药师培训理论考核试题(抗感染专业).doc.docx
- 学校生活-备战高考英语话题通关精准练(词汇+阅读+写作)(解析版).docx VIP
- 2024年初级会计职称《初级会计实务》精讲课件 第1-5章.pdf
- 史陶比尔机器人TX2-90用户手册.pdf
- 广西医科大学附属肿瘤医院临床药师培训基地学员理论考核(抗感染专业).docx
- 2024年-煤矿安全规程(精编).doc
文档评论(0)