###布局
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
###自定义2个fragment 里面分别写2个textview
### MainActivity
public class MainActivity extends FragmentActivity {
List<Fragment>list=new ArrayList<Fragment>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
//得到fragment管理者
FragmentManager fm = getSupportFragmentManager();
viewPager.setAdapter(new MyFragmentPagerAdapter( fm ,getFragment()));
}
/**
* @return
*/
private List<Fragment> getFragment() {
list.add(new Fragment1());
list.add(new Fragment2());
list.add(new Fragment1());
list.add(new Fragment2());
}
}