Implementation of Sliding Menu J. Feinstein
Asked Answered
B

1

8

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 !

Bereave answered 31/1, 2013 at 17:20 Comment(5)
This doesn't seem like an error with anything you posted. Where are you trying to inflate your fragments for the SlidingMenu?Pulsifer
@Pulsifer Thats what, I really don't understand where I made a mistake. Please suggest me somehing.Bereave
I suspect that you don't need to include your SlidingMenu in a RelativeLayout. Though, this is not a problem with SlidingMenu because it doesn't use fragments. Post your @layout/testing, I suspect that is where the problem is.Pulsifer
See my post, I have added testing.xml which has a simple textview. And testing_two.xml also has a simple textview in it.Bereave
@SrujanSimha did u solve this problem? if not, tel where have you used this menu_frame.xml ?Mendelism
G
4

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.

Gunilla answered 31/1, 2013 at 17:32 Comment(4)
I have jus added a layout testing.xml with a simple TextView in it. But still getting the same error.Bereave
Because your setting them to the same view again. Try setting them different views.Gunilla
As you said I created another xml with some text, but as usual, getting same error !Bereave
I tried your new update, but didnt work in my case. Is it that I have to do something with Fragments?Bereave

© 2022 - 2024 — McMap. All rights reserved.