0

我搜索了很多,但找不到这个问题的答案:有没有办法在 ViewPager 下方使用 TitlePageIndicator?

我在 .xml 中尝试了相反的顺序,但得到了:

04-24 19:30:30.288: E/AndroidRuntime(3338): FATAL EXCEPTION: main
04-24 19:30:30.288: E/AndroidRuntime(3338): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.totvs.android/br.com.totvs.android.ecm.activity.TelaPrincipalActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.os.Looper.loop(Looper.java:130)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at java.lang.reflect.Method.invoke(Method.java:507)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at dalvik.system.NativeStart.main(Native Method)
04-24 19:30:30.288: E/AndroidRuntime(3338): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at br.com.totvs.android.ecm.activity.TelaPrincipalActivity.onCreate(TelaPrincipalActivity.java:56)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-24 19:30:30.288: E/AndroidRuntime(3338):     ... 11 more
04-24 19:30:30.288: E/AndroidRuntime(3338): Caused by: java.lang.ClassCastException: com.viewpagerindicator.TitlePageIndicator
04-24 19:30:30.288: E/AndroidRuntime(3338):     at br.com.totvs.android.ecm.fragment.TabFragment.onCreateView(TabFragment.java:36)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:270)
04-24 19:30:30.288: E/AndroidRuntime(3338):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-24 19:30:30.288: E/AndroidRuntime(3338):     ... 18 more

提前致谢,

4

1 回答 1

2

这可能取决于您使用的 TitlePageIndicator 类型。但是我听说过的所有版本(包括可能是 Jake Wharton 中最受欢迎的版本)都只是视图,您可以将其放在任何您想要的地方。

所以你可以膨胀这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1">
    </android.support.v4.view.ViewPager>

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/titles"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />



</LinearLayout>

还有来自 Commonsware 的一个非常重要的说明。项目->清洁

于 2012-04-24T19:27:53.463 回答