Android官方文档阅读之旅——Animation and Graphics Overview 动画与图形概述

来源:互联网 发布:淘宝金鹰男士 假货 编辑:程序博客网 时间:2024/05/17 04:53

Animation and Graphics Overview (动画与图形概述)

原文地址:http://developer.android.com/guide/topics/graphics/overview.html

Android provides a variety of powerful APIs for applying animation to UI elements and drawing custom 2D and 3D graphics. The sections below provide an overview of the APIs and system capabilities available and help you decide with approach is best for your needs.

Android 提供了丰富强大的API,这些API可被用于设置UI元素动画以及绘制自定义二维或三维图形。本节提供了对这些API的概述、可获得的系统特性以及通过某些方法帮你决定选择那个API最适合你。

Animation 动画

The Android framework provides two animation systems: property animation (introduced in Android 3.0) and view animation. Both animation systems are viable options, but the property animation system, in general, is the preferred method to use, because it is more flexible and offers more features. In addition to these two systems, you can utilize Drawable animation, which allows you to load drawable resources and display them one frame after another.

安卓框架层提供了两种不同的动画属性:属性动画(于Android 3.0 引入)和控件动画。这两种动画系统都是可行的。但是总的来说,属性动画是首选。因为它更加灵活易用,并且更具特性。除了这两种系统外,你也可以使用帧动画,它允许你加载drawable资源并逐帧播放它们。

Property Animation 属性动画

Introduced in Android 3.0 (API level 11), the property animation system lets you animate properties of any object, including ones that are not rendered to the screen. The system is extensible and lets you animate properties of custom types as well.

于Android 3.0(第11级API)引入的属性动画系统允许你对任何对象的属性设置动画,包括那些未被屏幕显示的对象。这套系统是弹性的,它也允许你对自定义的属性进行动画设置。

View Animation 控件动画

View Animation is the older system and can only be used for Views. It is relatively easy to setup and offers enough capabilities to meet many application’s needs.

控件动画是一种较老的动画系统,它仅能被View(控件)使用,相对而言,它更容易被设置,并且具有满足多种应用需求的能力。

Drawable Animation 帧动画

Drawable animation involves displaying Drawable resources one after another, like a roll of film. This method of animation is useful if you want to animate things that are easier to represent with Drawable resources, such as a progression of bitmaps.

帧动画可以逐帧地播放drawable资源,如同一卷胶卷。如果你想播放那些可由Drawable资源更易于展示的动画,比如一些列位图,那么这种方法就是你的首选了。

2D and 3D Graphics 二维图形和三维图形

When writing an application, it’s important to consider exactly what your graphical demands will be. Varying graphical tasks are best accomplished with varying techniques. For example, graphics and animations for a rather static application should be implemented much differently than graphics and animations for an interactive game. Here, we’ll discuss a few of the options you have for drawing graphics on Android and which tasks they’re best suited for.

当编写一个APP时,想清楚你的图形需求是很必要的。不同的图形绘制任务最好由不同的技术实现。例如,对静态应用而言,其图形动画的实现必须有相当区别于一个可交互的游戏应用。这里,我们讨论下在Android中绘制图形的几种可选方式以及它们各自适用的场景。

Canvas and Drawables 画布和图形资源

Android provides a set of View widgets that provide general functionality for a wide array of user interfaces. You can also extend these widgets to modify the way they look or behave. In addition, you can do your own custom 2D rendering using the various drawing methods contained in the Canvas class or create Drawable objects for things such as textured buttons or frame-by-frame animations.

Android提供了一系列的View组件,这些组件可适用于多种UI界面。你也可以拓展这些组件并修改它们的形象以及动作。此外你也可以通过使用包含了Canvas类的多种绘制方法来创建自己的平面图形,或诸创建如带纹理按键以及逐帧动画的Drawable对象。

Hardware Acceleration 硬件加速

Beginning in Android 3.0, you can hardware accelerate the majority of the drawing done by the Canvas APIs to further increase their performance.

从Android 3.0开始,你可对绝大多数由Canvas API绘制的图形进行硬件加速,这样可以显著提高绘制的性能。

OpenGL (Open Graphics Library) 开放式图形库

Android supports OpenGL ES 1.0 and 2.0, with Android framework APIs as well as natively with the Native Development Kit (NDK). Using the framework APIs is desireable when you want to add a few graphical enhancements to your application that are not supported with the Canvas APIs, or if you desire platform independence and don’t demand high performance. There is a performance hit in using the framework APIs compared to the NDK, so for many graphic intensive applications such as games, using the NDK is beneficial (It is important to note though that you can still get adequate performance using the framework APIs. For example, the Google Body app is developed entirely using the framework APIs). OpenGL with the NDK is also useful if you have a lot of native code that you want to port over to Android. For more information about using the NDK, read the docs in the docs/ directory of the NDK download.

Android 系统支持OpenGL ES 1.0 和 2.0 版本,使用它需要借助于Android框架API或者原生开发组件NDK。当你需要添加一些图形增强效果于不支持Canvas API的应用中时,或者你希望平台独立性并且无需太高的性能表现的的话,可以选择使用框架API。想比较使用NDK而言,使用框架API会对性能造成严重影响。因此对于图形密集型应用(如游戏)而言,使用NDK更好(你也必须注意一点就是,使用框架API也可以获得足够的性能。例如Google Body应用就是完全由框架API实现的)。如果你有很多需要接入Android的原生代码,基于NDK的OpenGL就是一个很好的选择。对于使用NDK的更多信息,请参阅下载的NDK组件(或NDK开发文档全文)目录下对应部分的文档。


由于笔者水平有限,内容仅供参考,如有翻译不当之处,欢迎指正

0 0