android – 滑动菜单的实现J. Feinstein

我正在尝试使用jeremy feinstein的SlidingMenu库开发一个应用程序,我发现它非常有趣.我已经设置了所有内容并创建了一个示例项目,以检查我是否能够实现滑动菜单,但遗憾的是我在应用程序中看不到任何滑动菜单.

这些是我做的事情,

>从HERE下载SlidinMenu并导入到eclipse中作为
android现有项目.改变了谷歌API级别. (现在没有红色标记了.)
>创建了一个新项目,并向其添加了滑动菜单库.
>正如jfeinstein解释的那样,我将以下代码添加到我的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);

}

}

和我的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>

和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>

我已将他的menu.xml,shadow.xml,dimen.xml复制到我的项目中.

当我运行它时,我只看到了这些错误,

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

我不知道我犯了什么错误.尝试了很多,我无法在网上找出任何东西.任何形式的帮助或示例都非常感谢.
谢谢 !

解决方法

你的问题在这里.你的代码
sliding:viewAbove="@layout/menu_frame"
sliding:viewBehind="@layout/menu_frame"

从doc示例:

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

您必须确保上面的内容和视图背后的内容.

更新:我已经测试了你的代码,没有问题.我唯一要做的就是删除滑动:fadeEnabled =“true”因为编译错误.您可能希望查看代码中的其他位置或尝试删除该行并尝试.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...