我对android编程很新,我需要在android中使用SlidingPaneLayout帮助解决这个问题。我会附上一份日志。这是我的代码:
package com.anshikka.datagushalpha;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.View;
public class MainActivity extends FragmentActivity {
SlidingPaneLayout pane;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pane = (SlidingPaneLayout) findViewById(R.id.sp);
pane.setPanelSlideListener(new PaneListener());
if (!pane.isSlideable()) {
getFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(false);
getFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(true);
}
}
private class PaneListener extends FragmentActivity implements SlidingPaneLayout.PanelSlideLi stener {
@Override
public void onPanelClosed(View view) {
System.out.println("Panel closed");
getSupportFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(false);
getSupportFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(true);
}
@Override
public void onPanelOpened(View view) {
System.out.println("Panel opened");
getSupportFragmentManager().findFragmentById(R.id.leftpane).setHasOptionsMenu(true);
getSupportFragmentManager().findFragmentById(R.id.rightpane).setHasOptionsMenu(false);
}
@Override
public void onPanelSlide(View view, float arg1) {
System.out.println("Panel sliding");
}
}
}
//XML File for SlidingPaneLayout
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sp" >
<!-- Left side pane. (Master) -->
<fragment android:id="@+id/leftpane"
android:name="com.anshikka.datagushalpha
.slidingpanelayout.ListBookmarkFragment"
android:layout_width="190dp"
android:layout_height="match_parent"
android:layout_gravity="left" />
<!-- Right side page. (Slave) -->
<fragment android:id="@+id/rightpane"
android:name="com.anshikka.datagushalpha"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight="1"
/>
</android.support.v4.widget.SlidingPaneLayout>
// log
02-21 19:00:19.206: E/AndroidRuntime(16481): FATAL EXCEPTION: main
02-21 19:00:19.206: E/AndroidRuntime(16481): Process: com.anshikka.datagushalpha, PID: 16481
02-21 19:00:19.206: E/AndroidRuntime(16481): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anshikka.datagushalpha/com.anshikka.datagushalpha.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.os.Handler.dispatchMessage(Handler.java:102)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.os.Looper.loop(Looper.java:136)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.reflect.Method.invoke(Native Method)
02-21 19:00:19.206: E/AndroidRuntime(16481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-21 19:00:19.206: E/AndroidRuntime(16481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-21 19:00:19.206: E/AndroidRuntime(16481): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-21 19:00:19.206: E/AndroidRuntime(16481): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Activity.setContentView(Activity.java:1929)
02-21 19:00:19.206: E/AndroidRuntime(16481): at com.anshikka.datagushalpha.MainActivity.onCreate(MainActivity.java:14)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Activity.performCreate(Activity.java:5231)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-21 19:00:19.206: E/AndroidRuntime(16481): ... 9 more
02-21 19:00:19.206: E/AndroidRuntime(16481): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.anshikka.datagushalpha .slidingpanelayout.ListBookmarkFragment: make sure class name exists, is public, and has an empty constructor that is public
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Fragment.instantiate(Fragment.java:597)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Fragment.instantiate(Fragment.java:561)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Activity.onCreateView(Activity.java:4778)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-21 19:00:19.206: E/AndroidRuntime(16481): ... 19 more
02-21 19:00:19.206: E/AndroidRuntime(16481): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.anshikka.datagushalpha .slidingpanelayout.ListBookmarkFragment" on path: DexPathList[[zip file "/data/app/com.anshikka.datagushalpha-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.anshikka.datagushalpha-2, /vendor/lib, /system/lib]]
02-21 19:00:19.206: E/AndroidRuntime(16481): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
02-21 19:00:19.206: E/AndroidRuntime(16481): at android.app.Fragment.instantiate(Fragment.java:583)
02-21 19:00:19.206: E/AndroidRuntime(16481): ... 22 more
02-21 19:00:19.206: E/AndroidRuntime(16481): Suppressed: java.lang.ClassNotFoundException: Invalid name: com.anshikka.datagushalpha .slidingpanelayout.ListBookmarkFragment
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.Class.classForName(Native Method)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
02-21 19:00:19.206: E/AndroidRuntime(16481): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
02-21 19:00:19.206: E/AndroidRuntime(16481): ... 24 more