需要在android中创建像幻灯片一样的Facebook

时间:2013-07-20 07:33:42

标签: android android-fragments android-sliding

我正在尝试创建像滑动一样的Facebook我试过这个library似乎它对我不起作用..我需要像这样的屏幕..在滑动布局中的listview带有标题,同时点击它在相同的活动内容应该改变。实际上使用上面的库我尝试这样:

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

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

enter image description here

有人可以帮助我@thanks

4 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

仔细阅读:: https://github.com/jfeinstein10/SlidingMenu

这对你有帮助。

答案 2 :(得分:0)

在您的AndroidManifest.xml中,您已声明com.app.example.MainActivity,但您的活动名为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"
       >

答案 3 :(得分: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);

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