为什么Android中有两个Fragment类? [英] Why are there two Fragment classes in Android?

查看:107
本文介绍了为什么Android中有两个Fragment类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近的问题中,由于导入了android.app包中.解决该错误的方法是导入android.support.v4.app.Fragment.为什么会有两个不同的Fragment类似乎具有相同的功能?

In a recent question, the OP received an unexpected error message due to importing Fragment from the android.app package. The solution to fix the error was to import android.support.v4.app.Fragment instead. Why are there two different Fragment classes that appear to have the same functionality?

推荐答案

根据文档,片段是在Android 3.0(API 11)中引入的.大约在同一时间,Google还发布了Android支持库,允许开发人员在运行旧版Android的设备上使用片段和其他新API.该库包含的类具有与较新设备上的Android API附带的类完全相同的功能.由于这些库可以直接编译为APK文件,因此您不再需要依赖目标设备上可用的功能.现在,某些类仅可从支持库中获得,并且依赖于此库中的支持Fragment,而不是使用本机Fragment类,即使该类基本上在当前使用的所有设备上都可用.

According to the documentation, fragments were introduced in Android 3.0 (API 11). Around the same time, Google also released the Android Support Library which allowed developers to use fragments and other new APIs on devices that ran older versions of Android. This library contained classes with the exact same functionality as classes that shipped with the Android API on newer devices. Since these libraries can be compiled directly into your APK file, you no longer have to rely on the features being available on the target device. Some classes are now only available from the Support Library and rely on the support Fragment from this library rather than using the native Fragment class even though it is available on basically all devices now in use.

这篇关于为什么Android中有两个Fragment类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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