深入浅析 Android Fragment(上篇)

2019-12-10 19:59:26王旭

MainActivity

 

 
  1. package com.zhy.zhy_fragments;   import android.app.Activity;  
  2. import android.os.Bundle;   import android.view.Window;  
  3. public class MainActivity extends Activity   {  
  4. @Override  protected void onCreate(Bundle savedInstanceState)  
  5. {   super.onCreate(savedInstanceState);  
  6. requestWindowFeature(Window.FEATURE_NO_TITLE);   setContentView(R.layout.activity_main);  
  7. }   } 

Activity的布局文件:

 

 
  1. <RelativeLayout xmlns:android="http://www.easck.com/apk/res/android"  xmlns:tools="http://www.easck.com/tools" 
  2. android:layout_width="match_parent"  android:layout_height="match_parent" >  
  3. <fragment   android:id="@+id/id_fragment_title" 
  4. android:name="com.zhy.zhy_fragments.TitleFragment"  android:layout_width="fill_parent" 
  5. android:layout_height="45dp" />   <fragment  
  6. android:layout_below="@id/id_fragment_title"  android:id="@+id/id_fragment_content" 
  7. android:name="com.zhy.zhy_fragments.ContentFragment"  android:layout_width="fill_parent" 
  8. android:layout_height="fill_parent" />   </RelativeLayout>