Reputation: 319
I'm using jfeinstein10 - SlidingMenu. I have already implemented it using a normal handset but when I try my application in a tablet, it still shows the slide button. I followed the tutorial at ResponsiveUI but my menu is still hiding. I want it to be permanently shown when I am using a tablet. Shouldn't be menu_frame.xml automatically be called when using tablets? I tried commenting the part where it ask if menu_frame is null to force it to act in my tablet, but an error shows the menu_frame is not found. I'm confused at how sliding menu really works. Please help! Any idea why is it acting like that in tablet? Here are my source codes:
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);
}
layout/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" />
layout/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" />
Upvotes: 1
Views: 1130
Reputation: 319
I finally got the answer. Of course menu_frame can not just be added magically; You have to setup your xml at layout-large and layout-large-land for the menu_frame to appear at a tablet.
Upvotes: 1