Android滑动菜单在平板电脑上不起作用;菜单的作用就像在正常的手机(滑动按钮点击)



我使用jfeinstein10 - SlidingMenu。我已经用普通的手机实现了这个功能,但当我在平板电脑上试用我的应用程序时,它仍然显示滑动按钮。我遵循了ResponsiveUI的教程,但我的菜单仍然隐藏。当我使用平板电脑时,我希望它能永久显示。使用平板电脑时不应该自动调用menu_frame.xml吗?我试图评论的部分,它问如果menu_frame是空的,以迫使它在我的平板电脑行动,但一个错误显示menu_frame没有找到。我对滑动菜单的工作原理感到困惑。请帮助!知道为什么它在平板电脑上是这样的吗?以下是我的源代码:

BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); 
getSupportActionBar().hide();
setContentView(R.layout.activity_base);
// check if the content frame contains the menu frame
if (findViewById(R.id.menu_frame) == null) {            
    setBehindContentView(R.layout.menu_frame);
    getSlidingMenu().setMode(SlidingMenu.LEFT);
    getSlidingMenu().setSlidingEnabled(true);
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    getSlidingMenu().setBehindWidthRes(R.dimen.sidebar_default_width);          
} else {
    // add a dummy view
    Log.v("BaseActivity", "menu not null");
    View v = new View(this);
    setBehindContentView(v);
    getSlidingMenu().setSlidingEnabled(false);
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    getSlidingMenu().setBehindWidthRes(R.dimen.sidebar_no_width);
}
// set the Above View Fragment
if (savedInstanceState != null) {
    mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
    mMenuPosition = savedInstanceState.getInt("menu_position");         
}
if (mContent == null) {
    mContent = new BirdsFragment();
    mMenuPosition = 0;
}   
getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.content_frame, mContent)
    .commit();
// set the Behind View Fragment
getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.menu_frame, new MenuListFragment())
    .commit();
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidthRes(R.dimen.shadow_width);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    sm.setFadeDegree(0.35f);
}

布局/activity_base.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"   
        tools:context=".BaseActivity">
<include layout="@layout/actionbar" />
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_below="@id/actionbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

布局/menu_frame.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/menu_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />   

我终于得到了答案。当然,menu_frame不能只是神奇地添加;您必须将您的xml设置为layout-large和layout-large-land,以便menu_frame显示在平板电脑上。

最新更新