Sliding menu on both sides with two separate lists
-
23-12-2019 - |
Pregunta
I am working in an app which has sliding menu on both sides. I tried using navigation drawer but was not able to bring the menu by pushing the main screen to right side as in facebook. So I used Slidingmenu library as in https://github.com/jfeinstein10/SlidingMenu/. That is working nicely But the Problem I am facing is that same list is on both sides. Plz help me how to bring separate lists for left menu and right menu.
Here is my code
sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setSecondaryMenu(R.layout.menu_frame_two);
getSupportFragmentManager()
.beginTransaction().replace(R.id.menu_frame_two, new SampleListFragment())
.commit();
In SampleListFragment class is have created dynamic list for left menu and in SampleListRight class for right menu. I could'nt bring SampleListRight class in my code. Plz help me......
Solución
Replace your code by this:
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
setBehindContentView(R.layout.menu_right);
getSupportFragmentManager().beginTransaction().replace(R.id.menuRight, new MenuRightFragment()).commit();
getSlidingMenu().setSecondaryMenu(R.layout.menu_left);
getSupportFragmentManager().beginTransaction().replace(R.id.menuLeft, new MenuLeftFragment()).commit();
create two separate lists in MenuRightFragment() and MenuLeftFragment() class.
Otros consejos
- MenuFragment is left fragment
- RightFragment is right fragment
Make a list in both fragment like as you want
sm = getSlidingMenu(); // set slidder mode sm.setMode(SlidingMenu.LEFT_RIGHT); sm.setShadowWidthRes(R.dimen.shadow_width); sm.setShadowDrawable(R.drawable.shadow); sm.setBehindOffsetRes(R.dimen.slidingmenu_offset); sm.setFadeDegree(0.35f); sm.setTouchModeAbove(SlidingMenu.LEFT); //set right slider mode sm.setSecondaryMenu(R.layout.right_main); // Setting the Behind Left View setBehindContentView(R.layout.left_main); if (savedInstanceState == null) { FragmentTransaction t = this.getSupportFragmentManager() .beginTransaction(); leftFragment = new MenuFragment(); t.replace(R.id.left_container, leftFragment, MenuFragment.TAG); t.commit(); } else { leftFragment = (ListFragment) this.getSupportFragmentManager() .findFragmentByTag(MenuFragment.TAG); } // Setting the Behind right View if (savedInstanceState == null) { FragmentTransaction t = this.getSupportFragmentManager() .beginTransaction(); rightFragment = new RightFragment(); t.replace(R.id.right_container, rightFragment, RightFragment.TAG); t.commit(); } else { rightFragment = (ListFragment) this.getSupportFragmentManager() .findFragmentByTag(RightFragment.TAG); }
use this layout for both left and right side drawer and in framelayout replace your fragment whichever you want...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/drawer_right"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<ListView
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>