我有一个问题。 我有一个片段,它膨胀了另外两个片段(片段A留下,片段B是正确的) 我想在用户将模式更改为纵向模式时隐藏片段A. 我在layout-port / xml中添加了一个DrawerLayout,并在我的Fragment中添加了NavigationDrawer的代码,但它不起作用。 有没有人有想法,如何实现它?
谢谢:)
答案 0 :(得分:0)
我用这段代码解决了第一个问题:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
orientation = newConfig.orientation;
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
FragmentA fragmentleft = new FragmentA();
FragmentB fragmentright = new FragmentB();
FragmentTransaction transaction1 = getSupportFragmentManager()
.beginTransaction();
FragmentTransaction transaction2 = getSupportFragmentManager()
.beginTransaction();
transaction1.replace(R.id.framelayout_left, fragmentleft);
transaction2.replace(R.id.framelayout_right, fragmentright);
transaction1.commit();
transaction2.commit();
break;
case Configuration.ORIENTATION_PORTRAIT:
createNavigationDrawer();
Log.d("TEST", "Portrait");
break;
}
}
但是现在我遇到了问题,我必须在DrawerLayout的ListView中夸大FragmentA:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/framelayout_right"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/framelayout_left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
但我怎么能这样做? 它无法正常工作:( 我还试图将ListView更改为FrameLayout并在其中膨胀FragmentA,但它也不起作用:(
如果有人能帮助我,我会非常感激。)