是不是把Fragment当成普通的View一样声明在Activity的布局文件中,然后所有控件的事件处理等代码都由各自的Fragment去处理,瞬间觉得Activity好干净有木有~~代码的可读性、复用性以及可维护性是不是瞬间提升了~~~下面看下效果图:

4、动态的使用Fragment
上面已经演示了,最简单的使用Fragment的方式~下面介绍如何动态的添加、更新、以及删除Fragment
为了动态使用Fragment,我们修改一下Actvity的布局文件,中间使用一个FrameLayout,下面添加四个按钮~~~嘿嘿~~不是微信的按钮- -!
- <RelativeLayout xmlns:android="http://www.easck.com/apk/res/android" xmlns:tools="http://www.easck.com/tools"
- android:layout_width="match_parent" android:layout_height="match_parent" >
- <fragment android:id="@+id/id_fragment_title"
- android:name="com.zhy.zhy_fragments.TitleFragment" android:layout_width="fill_parent"
- android:layout_height="45dp" /> <include
- android:id="@+id/id_ly_bottombar" android:layout_width="fill_parent"
- android:layout_height="55dp" android:layout_alignParentBottom="true"
- layout="@layout/bottombar" /> <FrameLayout
- android:id="@+id/id_content" android:layout_width="fill_parent"
- android:layout_height="fill_parent" android:layout_above="@id/id_ly_bottombar"
- android:layout_below="@id/id_fragment_title" /> </RelativeLayout>










