我有一个左侧带有按钮的两个面板布局。当按下一个按钮时,右侧会显示相应的碎片。有时,这些碎片会重叠,但这是偶发性的问题。我不能一直复制它,但确实会发生。
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageButtonSettingsManageBooks:
SettingsManageBooksFragment mbFragment = new SettingsManageBooksFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, mbFragment).addToBackStack(null).commit();
mImgFragmentTitle.setImageResource(R.drawable.manage_my_books);
this.getSupportFragmentManager().executePendingTransactions();
break;
case R.id.imageButtonSettingsPurchaseHistory:
SettingsPurchaseHistoryFragment phFragment = new SettingsPurchaseHistoryFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, phFragment).commit();
mImgFragmentTitle.setImageResource(R.drawable.purchase_history);
this.getSupportFragmentManager().executePendingTransactions();
break;
case R.id.imageButtonSettingsAudio:
SettingsAudioFragment aFragment = new SettingsAudioFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, aFragment).commit();
mImgFragmentTitle.setImageResource(R.drawable.audio);
this.getSupportFragmentManager().executePendingTransactions();
break;
case R.id.imageButtonSettingsRestore:
SettingsRestoreFragment rFragment = new SettingsRestoreFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, rFragment).commit();
mImgFragmentTitle.setImageResource(R.drawable.restore);
this.getSupportFragmentManager().executePendingTransactions();
break;
case R.id.imageButtonSettingsCopyright:
SettingsCopyrightFragment cFragment = new SettingsCopyrightFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, cFragment).commit();
mImgFragmentTitle.setImageResource(R.drawable.copyright);
this.getSupportFragmentManager().executePendingTransactions();
break;
case R.id.imageButtonSettingsAbout:
SettingsAboutFragment abFragment = new SettingsAboutFragment();
getFragmentManager().beginTransaction().replace(R.id.setting_detail_container2, abFragment).commit();
mImgFragmentTitle.setImageResource(R.drawable.about);
this.getSupportFragmentManager().executePendingTransactions();
break;
看起来是因为我用新的片段替换了每个片段,这可能会导致重叠。在提交新片段之前,有没有一种清除所有片段的方法?
android:background="@android:color/black"
。 - Huy Tower