Android.app Fragments vs. android.support.v4.app 使用 ViewPager? [英] Android.app Fragments vs. android.support.v4.app using ViewPager?

查看:17
本文介绍了Android.app Fragments vs. android.support.v4.app 使用 ViewPager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Android 支持库、片段的问题,作为一个具体的例子,ViewPager 类.我的目的是创建一个应用程序,其功能与 Android 开发者网站 (http://developer.android.com/training/animation/screen-slide.htmlhttp://developer.android.com/training/implementing-navigation/lateral.html).查看他们的代码,我注意到他们使用了 android.support.v4.app 库,根据我的研究,这是访问 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.

在我的情况下,我对向后兼容性不感兴趣.最低 API 级别为 14(Ice Cream Sandwich),构建目标为 4.2 Jelly Bean.在最简单的形式中,我的应用与我在 Android 开发网站上链接的第二个演示完全一样 - 只需在三个标签之间滑动,每个标签都有内容.

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.

我读过的所有文章/帖子/答案似乎都非常喜欢 v4 支持库.现在我的问题虽然冗长,但问题是:

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):

  1. 构建我的应用程序的最佳方式是什么 - 使用 android.support.v4.app,从而使用 SupportFragments,或使用 android.app<中提供的 Fragments/code> - 为什么?

  1. 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?

如果来自 android.app 的 Fragment 是要走的路,那么接近 ViewPagers 的最佳方式是什么?

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

如果 SupportFragments 最适合该任务,我估计它们具有与其他相同的功能 - 那么将它们放在 android.app 中的目的是什么?

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...

推荐答案

您可以将 ViewPagerandroid.app 包中的原生片段与 android.app 包中的适配器一起使用一个 href="http://developer.android.com/reference/android/support/v13/app/package-summary.html" rel="noreferrer">android.support.v13.app 包.为此,您必须使用 v13 支持 jar.

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.

有两个版本的适配器可以与 ViewPager 一起使用,v4 包中的那些旨在与支持片段一起使用, 中的那些v13 带有原生片段.

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.

现在有两个片段实现的原因是历史性的:android.app 包中的片段是在 Android 3 中引入的,仅适用于平板电脑,并且创建了支持库以将片段带到运行较旧的手机版本.在 Android 4 上,两者都有.

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.

根据我自己的经验,我建议使用支持片段,即使在为 Android 4 开发时也是如此.以下是一些原因:片段或支持片段?

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 Fragments vs. android.support.v4.app 使用 ViewPager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆