5.2.5 Fragment实例精讲——新闻(购物)类App列表Fragment的简单实现.pdfVIP

  • 43
  • 0
  • 约8.95千字
  • 约 10页
  • 2017-05-27 发布于天津
  • 举报

5.2.5 Fragment实例精讲——新闻(购物)类App列表Fragment的简单实现.pdf

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

文档评论(0)

1亿VIP精品文档

相关文档