Implementation of the J. Feinstein Sliding Menu

I am trying to develop an application using the jeremy feinstein SlidingMenu library, which I found very interesting. I created everything and created a sample project to check if I can implement a sliding menu, but, unfortunately, I did not see any sliding menu in my application.

this is what i did

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

  • Created a new project and added a library of sliding menus 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 copied it menu.xml , shadow.xml , dimen.xml into my project.

And when I ran 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 do not know where I was wrong. I tried a lot, and I could not understand anything on the Internet. Any help or example is greatly appreciated. Thanks!

+7
source share
1 answer

Your problem is here. Your code:

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

In the sample document:

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

You must make sure what is higher and what is beyond the point of view.

Update: I checked your code, no problem with it. The only thing I needed to do was remove sliding:fadeEnabled="true" due to a compilation error for me. You might want to look somewhere else in your code or try to delete this line and try.

+4
source

All Articles