Activity动态添加fragment

//1.获取FragmentManager对象
15.FragmentManager manager = getFragmentManager();
16.//2.获取FragmentTransaction对象
17.FragmentTransaction transaction = manager.beginTransaction();
18.//添加Fragment对象
19.transaction.add(R.id.relativeLayout1, new Fragment1(), "fragment1");
20.transaction.add(R.id.relativeLayout2, new Fragment2(), "fragment2");
21.//4.提交
22.transaction.commit();

你可能感兴趣的:(android)