3、静态的使用Fragment
嘿嘿,终于到使用的时刻了~~
这是使用Fragment最简单的一种方式,把Fragment当成普通的控件,直接写在Activity的布局文件中。步骤:
1、继承Fragment,重写onCreateView决定Fragemnt的布局
2、在Activity中声明此Fragment,就当和普通的View一样
下面展示一个例子(我使用2个Fragment作为Activity的布局,一个Fragment用于标题布局,一个Fragment用于内容布局):
TitleFragment的布局文件:
- <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://www.easck.com/apk/res/android"
- android:layout_width="match_parent" android:layout_height="45dp"
- android:background="@drawable/title_bar" > <ImageButton
- android:id="@+id/id_title_left_btn" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:layout_centerVertical="true"
- android:layout_marginLeft="3dp" android:background="@drawable/showleft_selector" />
- <TextView android:layout_width="fill_parent"
- android:layout_height="fill_parent" android:gravity="center"
- android:text="我不是微信" android:textColor="#fff"
- android:textSize="20sp" android:textStyle="bold" />
- </RelativeLayout>
TitleFragment
- package com.zhy.zhy_fragments; import android.app.Fragment;










