我正在使用图书馆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;
}
}
答案 0 :(得分:1)
当我同时使用Left
和Right
SlidingMenu
时,我从未遇到过此问题但是对于您的问题,您可以查看SlidingMenu Issues并尝试{{3}你的问题的解决方案。它可能对你有帮助。
编辑:
试试这个
您需要一个调用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);
}
});