0

我正在使用库 jfeinstein 中的滑动菜单,我的活动中有两个滑动菜单“menuLeft”“menuRight”,一个从左侧,一个从右侧,我有相应滑动菜单的切换按钮,但是如果 menuLeft打开并且如果我从右向左滑动以关闭 menuLeft,menuRiht 也被打开,有什么办法可以避免这种不当行为这是我的活动,其中包含 SlidingMenu

public class ChatListActivity extends SherlockActivity {

    private SlidingMenu menuLeft;
    private SlidingMenu menuRight;
    private Button btnSliderLeftToggle;
    private Button btnSliderRightToggle;
    private ListView lvSliderLeft;
    private ListView lvSliderRight;
    private int width;
    private int height;
    private DBContacts db;

    @Override
        protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.chatlist_layout);
        db = new DBContacts(this);

        WindowManager wmanager = (WindowManager) getSystemService(WINDOW_SERVICE);
        Display display = wmanager.getDefaultDisplay();
        width = display.getWidth();
        height = display.getHeight();
        menuLeft = new SlidingMenu(this);
        menuRight = new SlidingMenu(this);
        initLeftSlider();
        initRightSlider();
        btnSliderLeftToggle = (Button) findViewById(R.id.mnuSlidingleftToggle);
        btnSliderLeftToggle.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v)
        {
            ChatListActivity.this.menuLeft.toggle();
        }
    });

    btnSliderRightToggle = (Button) findViewById(R.id.mnuSlidingRightToggle);
    btnSliderRightToggle.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            ChatListActivity.this.menuRight.toggle();

        }
    });

    menuLeft.setOnOpenedListener(new OnOpenedListener()
    {

        @Override
        public void onOpened()
        {
            lvSliderLeft = (ListView) findViewById(R.id.lvSlidingmenuLeft);
            MySLidingMenuLeftAdapter adapter = new MySLidingMenuLeftAdapter(ChatListActivity.this,
                    R.layout.crow_listview_lvslidingleft_chatlist);
            lvSliderLeft.setAdapter(adapter);
        }
    });

    menuRight.setOnOpenedListener(new OnOpenedListener()
    {

        @Override
        public void onOpened()
        {
            lvSliderRight = (ListView) findViewById(R.id.lvSlidingmenuRight);
            String column[] = new String[] { DBContacts.USERNAME};
            int[] viewId = { R.id.txtContactName};
            Cursor dataBaseCursor = db.getAllContacts();
            MySLidingMenuRightAdapter customContactListAdapter = new MySLidingMenuRightAdapter(
                    ChatListActivity.this, R.layout.crow_lvslidingmenu_right_chatlist, dataBaseCursor, column,
                    viewId, 0);
            lvSliderRight.setAdapter(customContactListAdapter);
        }
    });

}

private void initRightSlider()
{

    menuRight.setMode(SlidingMenu.RIGHT);
    menuRight.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menuRight.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menuRight.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menuRight.setMenu(R.layout.sliding_menu_chatlist_right);
    menuRight.setFadeDegree(0.35f);

}

private void initLeftSlider()
{

    menuLeft.setMode(SlidingMenu.LEFT);
    menuLeft.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menuLeft.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menuLeft.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menuLeft.setMenu(R.layout.sliding_menu_chatlist_left);
    menuLeft.setFadeDegree(0.35f);

}

@Override
public void onBackPressed()
{
    super.onBackPressed();
    System.exit(0);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    menu.add("Refresh");
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    new SendNativeContacts(this).execute();
    return true;
}
}
4

1 回答 1

1

当我同时使用这两种方法时,我从未遇到过这个问题LeftRight SlidingMenu但是对于您的问题,您可以查看SlidingMenu 问题,您可以尝试使用解决方案来解决您的问题。它可能会帮助你。

编辑 :

试试这个

您将需要一个补丁,它为右侧菜单调用 onOpened 和 onClosed 方法,它可能已包含在最新代码中。编写日志以检查方法调用。

slidingMenuLeft.setOnOpenedListener(new OnOpenedListener() {

            @Override
            public void onOpened(int pos) {
               slidingMenuRight.setSlidingEnabled(false);

            }
});

slidingMenuLeft.setOnClosedListener(new OnClosedListener() {

            @Override
            public void onClosed() {
                slidingMenuRight.setSlidingEnabled(true);

            }
        });

slidingMenuRight.setOnOpenedListener(new OnOpenedListener() {

            @Override
            public void onOpened(int pos) {
               slidingMenuLeft.setSlidingEnabled(false);

            }
});

slidingMenuRight.setOnClosedListener(new OnClosedListener() {

            @Override
            public void onClosed() {
                slidingMenuLeft.setSlidingEnabled(true);

            }
        });
于 2013-09-26T07:13:27.960 回答