Implementation of Sliding Menu J. Feinstein

Srujan Simha picture Srujan Simha · Jan 31, 2013 · Viewed 9.6k times · Source

I'm trying to develop an application using jeremy feinstein's SlidingMenu library which I found very interesting. I have set up everything and created a sample project just to check whether i'm able to implement the sliding menu, but unfortunately I couldn't see any sliding menu in my application.

these are the things what I did,

  • downloaded SlidinMenu from HERE and imported into eclipse as an android existing project. Changed its google api level. (Now no more red mark on it.)

  • Created a new project, and added the sliding menu library to it.

  • As jfeinstein explained, I added the following code to my MainActivity.java

    public class MainActivity extends Activity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setTitle("Title !");
    
        setContentView(R.layout.activity_main);
    
        SlidingMenu menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setShadowWidthRes(R.dimen.shadow_width);
        menu.setShadowDrawable(R.drawable.shadow);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.35f);
        menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        menu.setMenu(R.layout.menu);
    
    }
    

    }

and my activity_main.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=".MainActivity" >


<com.slidingmenu.lib.SlidingMenu
    xmlns:sliding="http://schemas.android.com/apk/res-auto"
    android:id="@+id/slidingmenulayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    sliding:viewAbove="@layout/testing"
    sliding:viewBehind="@layout/testing_two"
    sliding:touchModeAbove="margin"
    sliding:behindWidth="@dimen/shadow_width"
    sliding:behindScrollScale="0.5"
    sliding:shadowDrawable="@drawable/shadow"
    sliding:shadowWidth="@dimen/shadow_width"
    sliding:fadeEnabled="true"
    sliding:selectorEnabled="true"/>

</RelativeLayout>

and menu_frame.xml

<?xml version="1.0" encoding="utf-8"?>
<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" />

testing.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test"/>
</LinearLayout>

and I have copied his menu.xml, shadow.xml, dimen.xml into my project.

And when I run it I saw nothing but these errors,

01-31 22:18:13.027: E/AndroidRuntime(759): FATAL EXCEPTION: main
01-31 22:18:13.027: E/AndroidRuntime(759): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.demo.com/android.demo.com.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

I don't know where I made a mistake. Tried a lot and I couldnt figure out anything online. Any kind of help or example is much appreciated. Thanks !

Answer

wtsang02 picture wtsang02 · Jan 31, 2013

Your problem is here.Your code:

sliding:viewAbove="@layout/menu_frame"
sliding:viewBehind="@layout/menu_frame"

From the doc example:

sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"
sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"

You have to make sure what is above and what is behind the view.

Update: I have tested your code, there are no problem with it. The only thing I had to do was delete sliding:fadeEnabled="true" because of compile error for me. You might want to look at somewhere else in your code or try to delete that line and try.