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

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

问题描述

我有关于Android的支持库,碎片的问题,并作为一个具体的例子, ViewPager 类。我的目的是创建具有相似的功能,以提供对Android开发者网站上的样品的应用程序(<一href="http://developer.android.com/training/animation/screen-slide.html">http://developer.android.com/training/animation/screen-slide.html或<一href="http://developer.android.com/training/implementing-navigation/lateral.html">http://developer.android.com/training/implementing-navigation/lateral.html).展望自己的code,我注意到他们利用 android.support.v4.app <​​/ code>库,它从我的研究是访问<$的唯一途径C $ C> 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(冰淇淋三明治)和构建目标是4.2果冻豆。在它最简单的形式,我的应用程序执行完全一样的第二次演示中,我挂在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支持库。现在对于我,虽然长篇大论,问题(S):

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 <​​/ code>,从而使用SupportFragments,或使用所提供的片段 android.app <​​/ 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 <​​/ code>片段是要走的路,什么是接近最优的方式 ViewPagers

如果SupportFragments是最适合的任务,我估计他们拥有相同的功能与其他 - 所以有什么让他们在里面所有的目的 android.app <​​/ code>?

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

在此先感谢!

推荐答案

您可以使用 ViewPager 原生片段从 android.app <​​/ code>包从<一个适配器href="http://developer.android.com/reference/android/support/v13/app/package-summary.html">android.support.v13.app包。你必须使用V13支持罐子的。

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

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