0

我正在尝试创建像滑动一样的 facebook 我已经尝试过这个似乎对我不起作用..我需要像这个屏幕这样的东西..在滑动布局中,带有标题的列表视图,而在相同的活动内容中单击它应该会改变.实际上使用上面的库我试过这样:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.attach);
        // set the content view
        setContentView(R.layout.content);
        // configure the SlidingMenu
        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);
    }

}

这根本不起作用!错误:

07-20 10:17:19.776: E/AndroidRuntime(1134): FATAL EXCEPTION: main
07-20 10:17:19.776: E/AndroidRuntime(1134): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.example/com.app.example.MainActivity}: java.lang.IllegalStateException: Both setBehindContentView must be called in onCreate in addition to setContentView.
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.os.Looper.loop(Looper.java:137)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invokeNative(Native Method)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at java.lang.reflect.Method.invoke(Method.java:511)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at dalvik.system.NativeStart.main(Native Method)
07-20 10:17:19.776: E/AndroidRuntime(1134): Caused by: java.lang.IllegalStateException: Both setBehindContentView must be called in onCreate in addition to setContentView.
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityHelper.onPostCreate(SlidingActivityHelper.java:55)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity.onPostCreate(SlidingActivity.java:36)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1143)
07-20 10:17:19.776: E/AndroidRuntime(1134):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
07-20 10:17:19.776: E/AndroidRuntime(1134):     ... 11 more

菜单xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.app.example.SampleListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</fragment>

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.example"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         android:theme="@style/Theme.Myactionbar" 
        >
        <activity
            android:name="com.app.example.MainActivity"
            android:configChanges="orientation|screenSize|screenLayout"
           >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>



</manifest>

在此处输入图像描述

有人可以帮我吗@thanks

4

4 回答 4

1

通过这个http://developer.android.com/design/patterns/navigation-drawer.html不需要额外的 3rd 方库

于 2013-07-20T10:47:47.127 回答
0

包含您希望在滑动菜单中显示的列表视图的布局应该使用setBehindContentView(R.layout.yourlistlayout);您可以setcontentview()在代码中执行的设置。

您可以像这样将标题添加到您的列表视图

 TextView header = new TextView(this);
header.setText("Effects");
header.setTextColor(Color.WHITE);
header.setPadding(10, 10, 10, 10);
header.setTextSize(20);
header.setBackgroundColor(Color.parseColor("#054472"));
lv.addHeaderView(header);

作为替代方案,您可以NavigationDrawer在最近的 API 中使用 google 提供的新 API。但它同样不适用于旧版本的 android,这意味着您必须使用库(如 ActioBarSherlock)来实现向后兼容性。所以这取决于你。这是导航抽屉的链接。 http://developer.android.com/training/implementing-navigation/nav-drawer.html

于 2013-07-20T10:41:48.813 回答
0

在您的 AndroidManifest.xml 中,您已声明com.app.example.MainActivity但您的 Activity 已命名com.app.example.SlidingExample

改变

<activity
        android:name="com.app.example.MainActivity"
        android:configChanges="orientation|screenSize|screenLayout"
       >

<activity
        android:name="com.app.example.SlidingExample"
        android:configChanges="orientation|screenSize|screenLayout"
       >
于 2013-07-20T09:19:32.833 回答
0

通过这个:: https://github.com/jfeinstein10/SlidingMenu

这肯定会对你有所帮助。

于 2013-07-20T08:42:02.390 回答