我正在使用 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" />