我正在尝试使用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
我不知道我犯了什么错误.尝试了很多,我无法在网上找出任何东西.任何形式的帮助或示例都非常感谢.
谢谢 !