fragment中添加fragment与activity中添加fragment的不同

activity中添加fragment

FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container,rentFragment).commit();

或者transaction.add(R.id.fragment_container,rentFragment).show.commit();

fragment中添加fragment

FragmentManager manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();


// 把碎片添加到碎片中
 transaction.replace(R.id.llContainerfragment, fragment);
transaction.commit();

你可能感兴趣的:(Android基础)