case R.id.section:
int orientation = getResources().getConfiguration().orientation;
FrameLayout FragmentContainer = (FrameLayout) findViewById(R.id.FragmentContainer);
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
if (FragmentContainer.getVisibility() == View.VISIBLE) {
getSupportFragmentManager().beginTransaction().remove(new FragmentOne()).commit();
} else {
getSupportFragmentManager().beginTransaction().add(R.id.FragmentContainer, new FragmentOne()).commit();
}
break;
case Configuration.ORIENTATION_PORTRAIT:
if (FragmentContainer.getVisibility() == View.VISIBLE) {
getSupportFragmentManager().beginTransaction().remove(new FragmentTwo()).commit();
} else {
getSupportFragmentManager().beginTransaction().add(R.id.FragmentContainer, new FragmentTwo()).commit();
}
break;
}
我正在尝试根据我的框架布局的可见性删除/添加片段,但是当我单击菜单项时,没有任何反应......
下面是我在 XML 中定义的框架布局。
<FrameLayout
android:id="@+id/FragmentContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
我已经尝试add and replace
了片段的两种方法。