首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

【通译】(27)应用程序资源

2012-07-05 
【翻译】(27)应用程序资源【翻译】(27)应用程序资源?seehttp://developer.android.com/guide/topics/resources

【翻译】(27)应用程序资源

【翻译】(27)应用程序资源

?

see

http://developer.android.com/guide/topics/resources/index.html

?

原文见

http://developer.android.com/guide/topics/resources/index.html

?

-------------------------------

?

Application Resources

?

应用程序资源

?

Topics

?

主题

?

* Providing Resources 提供资源

* Accessing Resources 访问资源

* Handling Runtime Changes 处理运行时改变

* Localization 本地化

?

Reference?

?

参考

?

Resource Types 资源类型

?

You should always externalize resources such as images and strings from your application code, so that you can maintain them independently. Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations. In order to provide compatibility with different configurations, you must organize resources in your project's res/ directory, using various sub-directories that group resources by type and configuration.

?

你应该总是从你的应用程序中外部化资源诸如图片和字符串,使你可以独立地维护它们。外部化你的资源还允许你提供支持特定设备配置的可选资源诸如不同的语言或屏幕大小,这随着带有不同配置的更多基于Android的设备变得可用而变得日益重要。为了提供不同配置的兼容性,你必须在你的工程的res/目录下组织资源,使用不同的子目录根据类型和配置分组资源。

?

(图1略:

Android设备A

Android应用 默认资源

Android设备B

?

Figure 1. Two different devices, both using default resources.

?

图1. 两个不同的设备,都使用默认资源。

?

?

(图2略:

Android设备A

Android应用 默认资源 可选资源B

Android设备B

?

Figure 2. Two different devices, one using alternative resources.

?

图2. 两个不同的设备,其中有一个使用候选资源。

?

For any type of resource, you can specify default and multiple alternative resources for your application:

?

对于任意类型的资源,你可以为你的应用程序指定默认的和多个候选的资源:

?

* Default resources are those that should be used regardless of the device configuration or when there are no alternative resources that match the current configuration.

?

* 默认资源是那些应该在无需考虑设备配置或者在没有候选的资源匹配当前配置的时候使用的资源。

?

* Alternative resources are those that you've designed for use with a specific configuration. To specify that a group of resources are for a specific configuration, append an appropriate configuration qualifier to the directory name.

?

* 候选资源是那些你已经设计好用于特定配置的资源。为了指定一组资源用于一个特定的配置,请尾加一个合适的配置修饰符到目录名。

?

For example, while your default UI layout is saved in the res/layout/ directory, you might specify a different UI layout to be used when the screen is in landscape orientation, by saving it in the res/layout-land/ directory. Android automatically applies the appropriate resources by matching the device's current configuration to your resource directory names.

?

例如,当你的默认用户界面布局保存在res/layout/目录,你可以指定一个不同的用户界面布局在屏幕处于宽屏方向时使用,通过保存它在res/layout-land/目录下。Android通过匹配设备的当前配置到你的资源目录名,自动地应用合适的资源。

?

Figure 1 demonstrates how a collection of default resources from an application are applied to two different devices when there are no alternative resources available. Figure 2 shows the same application with a set of alternative resources that qualify for one of the device configurations, thus, the two devices uses different resources.

?

图1演示当没有可用的可选资源时,来自一个应用程序的一组默认资源如何被应用到两个不同的设备。图2展示带有一组分别修饰一种设备配置的可选资源的相同应用程序,这种情况下,两个设备使用不同的资源。

?

The information above is just an introduction to how application resources work on Android. The following documents provide a complete guide to how you can organize your application resources, specify alternative resources, access them in your application, and more:

?

上面的信息只是介绍应用程序资源是如何工作在Android上。以下文档提供一个完整的指引,关于你如何可以组织你的应用程序资源,指定候选资源,在你的应用程序中访问它们,以及更多:

?

* Providing Resources

?

* 提供资源

?

What kinds of resources you can provide in your app, where to save them, and how to create alternative resources for specific device configurations.

?

你可以在你的应用中提供哪些类型的资源,在哪里保存它们,以及如何为特定的设备配置创建候选资源。

?

* Accessing Resources

?

* 访问资源

?

How to use the resources you've provided, either by referencing them from your application code or from other XML resources.

?

如何使用你已经提供的资源,通过从你的应用程序代码中或者从其它XML资源中引用它们来做到。

?

* Handling Runtime Changes

?

* 处理运行时改变

?

How to manage configuration changes that occur while your Activity is running.

?

如何管理在你的Activity正在运行时发生的配置改变。

?

* Localization

?

* 本地化

?

A bottom-up guide to localizing your application using alternative resources. While this is just one specific use of alternative resources, it is very important in order to reach more users.

?

一个关于使用可选资源本地化你的应用程序的自下而上的指引。虽然这只是可选资源的一个特定用途,然而这对于接触更多用户来说非常重要。

?

* Resource Types

?

* 资源类型

?

A reference of various resource types you can provide, describing their XML elements, attributes, and syntax. For example, this reference shows you how to create a resource for application menus, drawables, animations, and more.

?

你可以提供的不同资源类型的参考文档,描述它们的XML元素、属性,以及语法。例如,这个参考文档向你展示如何为应用程序的菜单、可绘画对象、动画,以及更多东西创建一个资源。

?

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

?

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

?

Android 4.0 r1 - 21 Dec 2011 3:15

?

-------------------------------

?

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

?

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

?

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/

?

热点排行