Android.app Fragments vs. android.support.v4.app using ViewPager?

I have a question regarding the Android Support Libraries, Fragments, and as a specific example, the ViewPager class. My intention is to create an app with similar functionality to the sample provided on the Android Developer website (http://developer.android.com/training/animation/screen-slide.html or http://developer.android.com/training/implementing-navigation/lateral.html). Looking into their code, I've noticed they utilize the android.support.v4.app library, which from my research is the only way to access the ViewPager class.

In my situation, I have no interest in backward compatibility. The minimum API level is 14 (Ice Cream Sandwich) and the build target is 4.2 Jelly Bean. In it's simplest form, my app performs exactly as does the second demo I linked on the Android dev website - just swiping between three tabs with content in each.

All of the articles/posts/answers I've read seem to heavily favor the v4 support library . Now for my, albeit long-winded, question(s):

  • What's the best way to structure my application - using android.support.v4.app , and thereby using SupportFragments, or to use the Fragments provided in android.app - and why?

  • If Fragments from android.app are the way to go, what is the optimal way to approach ViewPagers ?

  • If SupportFragments are best-suited to the task, I would estimate that they possess the same functionality as the other - so what's the purpose of having them at all inside android.app ?

  • Hopefully someone with a clearer understanding can give me a bit of clarification because I'm boggled...


    You can use ViewPager with native fragments from the android.app package with the adapters from the android.support.v13.app package. You have to use the v13 support jar for that.

    There are two versions of the adapters that work with ViewPager , the ones in the v4 package are meant to be used with support fragments, the ones in v13 with native fragments.

    The reason why there are now two fragment implementations is historical: Fragments in the android.app package were introduced with Android 3 for tablets only and the support library was created to bring fragments to phones running older versions. On Android 4 you have both.

    From my own experience I would recommend using support fragments, even when developing for Android 4. Here are some reasons: Fragment or Support Fragment?


    android.app.Fragment类从Android P(链接)开始已被弃用,所以只有android.support.v4.app.Fragment应该在任何地方使用。


    If you're going to target API 11+, you won't need the support library [and your actual apk will be smaller, at least).

    If you want to support anything before Android 3.x, you'll need the support library.

    Is this what you're asking?

    链接地址: http://www.djcxy.com/p/68142.html

    上一篇: 片段中由ViewPager控制的片段不会显示

    下一篇: Android.app片段与android.support.v4.app使用ViewPager?