【发布时间】:2012-10-15 11:46:50
【问题描述】:
我遇到了ViewPager 和相关的FragmentPagerAdaptor,它们不是常规 Android 包的一部分,但仅在 V4 支持包中可用。看来我不能将 FragmentPagerAdaptor 与 android.app.Fragment 一起使用,因为 FragmentPagerAdaptor 需要 v4 FragmentManager 来实例化。阅读 Difference between Activity and FragmentActivity 这似乎是一致的 - 使用 v4 片段和相关类或常规 android.app.Fragments。切勿混合。
更进一步,我认为根本不需要使用常规的 android.app.Fragments,因为它们不如 v4 支持包强大。 (引用另一个问题:The Android Support package is not only for backports of newer APIs. It is also for other classes that, for whatever reason, are not being added to the SDK, such as ViewPager and its supporting classes.)。我能想到的“唯一”缺点是 v4 支持库与 APK 捆绑在一起,这意味着我的应用将占用更多空间。
我是否应该始终使用 v4 支持库来支持片段,因为它们包含更多功能? (而且它们是向后兼容的,不要忘记。)
【问题讨论】: