Android PagerTitleStrip无法显示

时间:2012-07-03 13:02:48

标签: android android-viewpager

我有基本的xml设置......

    <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">

    <android.support.v4.view.ViewPager
     android:id="@+id/viewpager"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center" >

    <android.support.v4.view.PagerTitleStrip
     android:id="@+id/pagertitlestrip"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="top" />
    </android.support.v4.view.ViewPager>

    </LinearLayout>

我在适配器中覆盖了getPageTitle。 我得到一个inflate pagertitlestrip错误。 我在这里错过了什么吗?

如果我删除了pagertitlestrip xml,则pageviewer可以正常处理多个片段。

logcat的:

    07-03 09:46:13.050: W/dalvikvm(23349): threadid=1: thread exiting with uncaught            exception (group=0x40018560)
    07-03 09:46:13.060: E/AndroidRuntime(23349): FATAL EXCEPTION: main
    07-03 09:46:13.060: E/AndroidRuntime(23349): java.lang.RuntimeException: Unable to  start activity ComponentInfo{org.example.walk/org.example.walk.AchieveViewPager}:  android.view.InflateException: Binary XML file line #12: Error inflating class  android.support.v4.view.PagerTitleStrip
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.os.Handler.dispatchMessage(Handler.java:99)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.os.Looper.loop(Looper.java:130)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread.main(ActivityThread.java:3806)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at java.lang.reflect.Method.invokeNative(Native Method)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at java.lang.reflect.Method.invoke(Method.java:507)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at dalvik.system.NativeStart.main(Native Method)
    07-03 09:46:13.060: E/AndroidRuntime(23349): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v4.view.PagerTitleStrip
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:260)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.Activity.setContentView(Activity.java:1716)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at org.example.walk.AchieveViewPager.onCreate(AchieveViewPager.java:22)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    ... 11 more
    07-03 09:46:13.060: E/AndroidRuntime(23349): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.PagerTitleStrip in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/org.example.walk-1.apk]
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
    07-03 09:46:13.060: E/AndroidRuntime(23349):    ... 21 more

1 个答案:

答案 0 :(得分:1)

听起来你要包括旧版本的compat库。试试v9。