您可以尝试在 FragmentActivity 中替换您的片段,这是部分编码的想法:假设您有这样的片段布局(main.xml):
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal">
<LinearLayout android:id="@+id/waiting" ...>
</LinearLayout>
<!-- hidden layout -->
<LinearLayout>
<LinearLayout android:id="@+id/layout_list_items" ...>
</LinearLayout>
<LinearLayout android:id="@+id/layout_detail" ...>
</LinearLayout>
</LinearLayout>
</LinearLayout>
你的 FragmentActivity 是这样的:
public class FragmentsActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
Fragment fragA = new WaitingTransaction();
FragmentTransaction fragTrans = this.getSupportFragmentManager().beginTransaction();
fragTrans.add(R.main.waiting, fragA);
fragTrans.commit();
}
private void afterProcessing(){
//show hidden layout and make the waiting hidden through visibility, then add the fragment bellow...
FragmentTransaction fragTrans = this.getSupportFragmentManager().beginTransaction();
fragTrans.add(R.main.layout_list_items,
new FragmentList());
fragTrans.replace(R.main.layout_detail,
new FragmentB());
fragTrans.commit();
}
}