【问题标题】:Sliding menu on both sides with two separate lists两侧有滑动菜单,带有两个单独的列表
【发布时间】:2014-02-27 05:12:34
【问题描述】:

我正在使用一个两侧都有滑动菜单的应用程序。我尝试使用导航抽屉,但无法像在 facebook 中那样通过将主屏幕推到右侧来显示菜单。所以我在https://github.com/jfeinstein10/SlidingMenu/ 中使用了Slidingmenu 库。效果很好但是我面临的问题是双方都有相同的列表。请帮助我如何为左侧菜单和右侧菜单带来单独的列表。

这是我的代码

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();      

在 SampleListFragment 类中为左侧菜单创建了动态列表,在 SampleListRight 类中为右侧菜单创建了动态列表。我不能在我的代码中引入 SampleListRight 类。 请帮帮我......

【问题讨论】:

  • 你用过Fragment类吗?
  • 是的@Shayan pourvatan。
  • 所以在那里处理或者为你的菜单调用不同的片段
  • 你也可以通过android默认drawerlayout实现这一点,而不使用库..

标签: android listview slider slidetoggle swipe-gesture


【解决方案1】:

用这个替换你的代码:

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();

在 MenuRightFragment() 和 MenuLeftFragment() 类中创建两个单独的列表。

【讨论】:

    【解决方案2】:
    1. MenuFragment 是左片段
    2. RightFragment 是右片段
    3. 根据需要在两个片段中创建一个列表

          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);
      }
      

    【讨论】:

    • 从屏幕中心滑动时菜单不打开,只有从边缘滑动时才有效
    • 嘿伙计只需更改它 sm.setTouchModeAbove(SlidingMenu.LEFT);到 sm.setTouchModeAbove(SlidingMenu.LEFT_RIGHT)
    【解决方案3】:

    将此布局用于左侧和右侧抽屉,并在 framelayout 中替换您想要的片段...

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多