xml视图参见
package com.example.androidtest; import android.app.Activity; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.os.Bundle; import android.view.Display; import android.view.WindowManager; public class FragmentsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragments); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); WindowManager wm = getWindowManager(); Display d = wm.getDefaultDisplay(); if(d.getWidth() > d.getHeight()){//landscape mode Fragment1 fragment1 = new Fragment1(); //android.R.id.content活动的内容视图 fragmentTransaction.replace(android.R.id.content, fragment1); }else{//portrait mode Fragment2 fragment2 = new Fragment2(); fragmentTransaction.replace(android.R.id.content, fragment2); } fragmentTransaction.commit(); } }