Android开发文档标准翻译(02)一Application Fundamentals

Application Fundamentals

Android apps are written in the Java programming language. The Android SDK tools compile your code—along with any data and resource files—into an APK: an Android package, which is an archive file with an .apk suffix. One APK file contains all the contents of an Android app and is the file that Android-powered devices use to install the app.

Andorid应用是用java设计语言写的。Android SDK工具把你代码-连同所有数据和资源文件文件编译成一个APK:一个Android包,这个一个是以.apk为后缀的归档文件。一个APK文件包含了一个android应用的所有内容和Android设备使用安装app的文件。


Once installed on a device, each Android app lives in its own security sandbox:

一旦安装到设备上,每一个Android应用存活在它自己的安全盒子里面:



1.The Android operating system is a multi-user Linux system in which each app is a different user.
2.By default, the system assigns each app a unique Linux user ID (the ID is used only by the system and is unknown to the app). The system sets permissions for all the files in an app so that only the user ID assigned to that app can access them.
3.Each process has its own virtual machine (VM), so an app's code runs in isolation from other apps.
4.By default, every app runs in its own Linux process. Android starts the process when any of the app's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other apps.

1.Android操作系统是一个多用户Linux系统,每个应用是一个不同的用户。
2.默认情况下,系统为每一个应用设计一个唯一的用户ID(这个ID只能在系统使用对应用程序并不可见)。系统为Android应用的所有文件设置权限,这样只用为应用分配用户ID才可以访问他们。
3.每个进程有自己的虚拟机(VM)。所以一个应用的代码和其它应用是分开运行的。
4.默认情况下,每一个应用运行在自己的Linux进程。当应用的任何组件需要执行时,Android会启动一个进程,然后关闭这个进程,当它不再需要或者系统为其它应用必须回收内存。


In this way, the Android system implements the principle of least privilege. That is, each app, by default, has access only to the components that it requires to do its work and no more. This creates a very secure environment in which an app cannot access parts of the system for which it is not given permission.

通过这种方式,Android系统实现最小优先原则。这样,,默认情况下,每一个应用只能访问它需要为它工作的组件而不再做其它事情,。这创建了一个非常好的安全坏境,一个应用不能访问系统没有给予权限的部分。


However, there are ways for an app to share data with other apps and for an app to access system services:

然而,有方法为一个应用和其它应用共享数据并且访问系统服务:


1.It's possible to arrange for two apps to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, apps with the same user ID can also arrange to run in the same Linux process and share the same VM (the apps must also be signed with the same certificate).
2.An app can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All app permissions must be granted by the user at install time.


1.它尽可能的把两个应用分享同一个Linux用户ID,在这种情况下,他们的文件能相互访问。为了节省系统资源,系统会把具有相同用户ID的应用运行在同一个Linux进程和共享同一个虚拟机(这个app也必须有相同签名证书)。 
2.一个应用需要权限去访问设备数据,例如用户联系人,SMS信息,可安装的储存卡(SD card),相机,蓝牙,和更多。所有应用权限必须通过用户安装时授予。



That covers the basics regarding how an Android app exists within the system. The rest of this document introduces you to:

这涵盖了有关于一个android应用怎样存在系统内的基本概念。这个文档的剩余部分为你介绍:

1.The core framework components that define your app.
2.The manifest file in which you declare components and required device features for your app.
3.Resources that are separate from the app code and allow your app to gracefully optimize its behavior for a variety of device configurations.

1.定义你的应用核心框架组件。
2.在manifest文件中为你的应用声明组件和需要设备特性。
3.来自应用代码的资源是分开的,允许让你的应用优雅的优化,它表现为多种设备配置。注:这句话我想了很久才理解。


App Components(应用组件)


App components are the essential building blocks of an Android app. Each component is a different point through which the system can enter your app. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your app's overall behavior.

应用组件是一个Androidy应用的基本构成块。每一个组件是不同的点系统通过这些点进入你的应用。对用户来说不是多有的组件都是实际的点并且有一些有依赖于其它点,但是每一个存在的组件都有它自己的入点并且扮演一个具体的角色---每一个组件是唯一的构成块帮助你定义所有的行为。


There are four different types of app components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

有四个不同类型的应用组件。每个类型服务一个不同的目的和有不同的生命周期,生命周期定义组件怎样创建和销毁。



Here are the four types of app components:

下面是四个类型的应用组件:



Activities(活动)


An activity represents a single screen with a user interface. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email app, each one is independent of the others. As such, a different app can start any one of these activities (if the email app allows it). For example, a camera app can start the activity in the email app that composes new mail, in order for the user to share a picture.

一个activity显示在一个单一的屏幕和一个用户界面。例如,一个email应用可能有一个activity,这个activity显示一个新的emails列表,另一个activity用于写邮件,还有一个activity阅读邮件。虽然activityies一起工作在email应用形成一个完整的用户体验,但是每个部分是相互独立的。像这样的,不同的应用会启动这些activities其中的任何一个(如果email应用允许它)。例如,一个照相应用能启动一个email应用中的activity组成一个新的email,为用户分享一张照片。


An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.

一个activity实现了Activity子类并且你会在Activities开发指南中学习更多。


Services(服务)


A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different app, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

一个服务是一个组件运行在后台去执行长时间运行的操作或者执行在远程进程的工作。一个服务没有提供一个用户界面。例如,用户在其它应用中,一个服务可能在后台播放音乐,或者它可能获取网络后台数据,这不影响用户和activity交互。另一组件,例如一个activity会启动一个服务让它运行或者绑定它为了和其它actiivty交互。


A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.

一个service 实现了Service 子类并且你会在Services开发指南中学习更多。




Content providers(内容提供商)


A content provider manages a shared set of app data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your app can access. Through the content provider, other apps can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any app with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.

一个content provider管理共享的应用数据集。你可以保存数据到系统文件总,一个SQLite数据库,在网上,或者你的应用可以访问的永久储存器中。通过内容提供商,其它的应用可以查询或者甚至修改这些数据(如果content provider 允许它)。例如,Android系统提供一个content provider管理用户联系人信息。这样的话,任何的应用用适当的权限可以查询content provider的一些部分(例如ContactsContract.Data)去阅读和写有关于详细的人信息。


Content providers are also useful for reading and writing data that is private to your app and not shared. For example, the Note Pad sample app uses a content provider to save notes.

为你的应用阅读和写入私有的非共享的数据内容提供商是非常有用的。例如Note Pad案例应用使用content provider保存笔记。



A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other apps to perform transactions. For more information, see the Content Providers developer guide.

一个content provider实现一个ContentProvider子类并且必须实现一条标准的APIS集合能够为其它应用执行事务。更多的信息,查看Content Provider开发文档。



Broadcast receivers(广播接收者)


A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Apps can also initiate broadcasts—for example, to let other apps know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

一个broadcast receiver是一个响应整个系统广播公告的组件。许多广播来自于系统。例如,一个关闭屏幕的广播公告,电池低,或者一张照片被捕获。应用也可以发送广播--例如,让其它应用知道一些数据被下载到设备上了并且他们可以使用了。虽然broadcast receivers不能显示一个用户界面,他们能创建一个通知状态栏用来引起用户注意,当一个broadcast事件发生时。更多情况下,一个broadcast receiver仅仅是个一种其它组件想要做很小的工作的途径。例如,它可能初始化一个服务去执行基时间的一些工作。


A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see the BroadcastReceiver class.

一个broadcast receiver是实现一个BroadcastReceiver子类并且每个广播发出一个Intent对象。更多的信息,查看BroadcastReceiver类。


A unique aspect of the Android system design is that any app can start another app’s component. For example, if you want the user to capture a photo with the device camera, there's probably another app that does that and your app can use it, instead of developing an activity to capture a photo yourself. You don't need to incorporate or even link to the code from the camera app. Instead, you can simply start the activity in the camera app that captures a photo. When complete, the photo is even returned to your app so you can use it. To the user, it seems as if the camera is actually a part of your app.

任何一个应用可以启动其它应用的组件是Android系统设计唯一的方面。例如,如果你想要用户在camera设备上拍摄一张照片,或许其它应用已经用这个功能,并且你的应用可以使用它,而你自己不再需要开发一个拍照的Activity。你不需要合并或者甚至链接cameray应用的代码。而只是,你可以简单地启动一个camera应用的activity用来拍照。当编译的完成时,甚至能返回一张照片给你的应用所以你可以使用它,对于用户来讲,camera看起来是你应用中一部分。


When the system starts a component, it starts the process for that app (if it's not already running) and instantiates the classes needed for the component. For example, if your app starts the activity in the camera app that captures a photo, that activity runs in the process that belongs to the camera app, not in your app's process. Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no main() function, for example).

当系统启动一个组件,它为这个应用启动一个进程(如果他没有已经运行)和实例化组件需要的类。例如,如果你的应用启动一个camera应用的activity来捕获照片,这个acitivity运行在属于camera应用的进程中,而不是在你应用进程中。因此,不像大多数系统其它应用,Android应用没有单个的进入入点(例如没有main()函数)。



Because the system runs each app in a separate process with file permissions that restrict access to other apps, your app cannot directly activate a component from another app. The Android system, however, can. So, to activate a component in another app, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

因为系统运行的每一个应用在一个文件权限的独立进程中,限制了去访问其他应用,你的应用不能直接访问其它应用的组件。然而,android系统可以触发其它应用的组件,你必须传送一个消息到系统指定你的Intent启动一个具体的组件。然后系统为你激活这个组件。



Activating Components(激活组件)

 


Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs to your app or another.

四个组件中的三个组件类型-activities,services,and broadcast receivers-是通过异步消息调用一个Intent激活的。在运行时Intent把个别组件和其它组件绑定(你可以认为他们是作为用于请求其它组件动作的一个信使),而不需要知道其中一个组件属于你的应用或者是其它应用。


An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.

一个Intent是创建一个Intent对象,定义一个消息激活任何一个指定的组件或者一个指定组件类型--一个Intent分别可以是显示的,隐式的其中一个。


For activities and services, an intent defines the action to perform (for example, to "view" or "send" something) and may specify the URI of the data to act on (among other things that the component being started might need to know). For example, an intent might convey a request for an activity to show an image or to open a web page. In some cases, you can start an activity to receive a result, in which case, the activity also returns the result in an Intent (for example, you can issue an intent to let the user pick a personal contact and have it returned to you—the return intent includes a URI pointing to the chosen contact).

关于activities和services,一个Intent定义执行的动作(例如,去“绘制”或者“发送”某些东西)并且可能指定URI数据动作(其中一些,是其他组件启动所需要知道的)。比如,一个Intent可能为一个activity传递一个请求去显示一张图片或者打开一个web页面。在某些情况下,你会启动一个activity去接收一个结果,在这种情况下,Activity还会返回一个Intent结果(例如,你可以发布一个Intent让你的用户挑选某个人的联系方式并返回结果给你--返回的Intent包含一个指定联系方式URI)。


For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates "battery is low").

关于broadcast receivers,这个Intent简单地定义广播公告(例如,一个广播指示设备电池低,它只包含了一个系统知道的动作字符串,表示"蓄电池低")。



The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver. The content resolver handles all direct transactions with the content provider so that the component that's performing transactions with the provider doesn't need to and instead calls methods on the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).

其它组件类型,content provider,不是通过intent激活的。相反地,它是由当一个ContentResolver请求目标时激活。这个ContentResolver. 处理所有有关content provider直接事务,因此那些不用provider执行事务的component不必要去调用ContentResolver对象的方法。这相当于在content provider和请求信息的component 之间留了一个抽象层(这是为了安全起见)。



There are separate methods for activating each type of component:

有分开的方法为激活每一个组件类型:


1.You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result).
2.You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing an Intent to bindService().
3.You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

4.You can perform a query to a content provider by calling query() on a ContentResolver.


1.你可以通过传递一个Intent给startActivity或者startActivityForResult()(当你想要在这个activity返回结果时)方法来启动activity(或者给它新的事情去做)。

2.你可以通过一个Intent给startService()方法启动一个服务(或者给一个新的指令给一个进行中的服务),或者你可以通过传递一个Intent给bindService()方法绑定服务。
3.你可以通过一个Intent给sendBroadcast(),sendOrdereBroadcast(),或者sendStickyBroacast()像这样的方法开始一个广播。
4.你可以通过在ContentResolver调用query()方法执行content provider查询。


For more information about using intents, see the Intents and Intent Filters document. More information about activating specific components is also provided in the following documents: Activities, Services, BroadcastReceiver and Content Providers.

有关于使用intent更多的信息,查看Intents和Intent Filters文档。下面文档提供了有关于激活指定的组件更多信息:Activities, Services, BroadcastReceiver and Content Providers。




The Manifest File(Manifest文件)


Before the Android system can start an app component, the system must know that the component exists by reading the app's AndroidManifest.xml file (the "manifest" file). Your app must declare all its components in this file, which must be at the root of the app project directory.

在Android系统会启动一个应用组件之前,系统必须知道那个组件是存在的。通过阅读应用的AndroidManifest.xml文件("manifest"文件)。你的应用必须在这个文件中声明所有的组件,这个文件必须在应用项目的根目录。 


The manifest does a number of things in addition to declaring the app's components, such as:

manifest文件除了声明应用组件还做了很多事情,例如:


1.Identify any user permissions the app requires, such as Internet access or read-access to the user's contacts.
2.Declare the minimum API Level required by the app, based on which APIs the app uses.
3.Declare hardware and software features used or required by the app, such as a camera, bluetooth services, or a multitouch screen.
4.API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.
5.And more

1.标识应用需要任何用户权限,例如网络访问和可读访问用户联系人权限。

2.通过应用声明需要最低的API级别,基于用户使用的API。
3.通过应用声明使用或者需要软件和硬件的特性,例如相机,蓝牙服务,或者屏幕多点触摸。
4.应用API库需要链接的(除了Android框架APIS),例如Google地图库。
5.和更多的。




Declaring components(声明组件)


The primary task of the manifest is to inform the system about the app's components. For example, a manifest file can declare an activity as follows:

manifest主要任务是通知系统应用的有关组件。例如,一个manifest文件可以声明一个activity像下面一样:








In the <application> element, the android:icon attribute points to resources for an icon that identifies the app.
在<application>元素中,这个android:icon属性指明了这个标识应用图标的资源。


In the <activity> element, the android:name attribute specifies the fully qualified class name of the Activity subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.

在<activity>元素中,这个android:name属性指定Activity子类的完整类名,android:label属性给activity指定了一个用于显示给用户的字符串标签。



You must declare all app components this way:

你必须通过这些方式声明所有的组件。



1.<activity> elements for activities
2.<service> elements for services
3.<receiver> elements for broadcast receivers

4.<provider> elements for content providers

1.为activities组件声明<activity>元素

2.为serices组件声明<service>元素
3.为broadcast receivers组件声明<receiver>元素
4.为content providers组件声明<provider>元素




Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().

在你的源代码包括Activitis,services,和content providers没有在manifest中声明对系统是不可视的,因此就不能运行。然而,broadcast receivers可以在manidfest声明或者在代码上动态创建(如BroadcastReceiver对象),系统通过调用registerReceiver()方法注册。


For more about how to structure the manifest file for your app, see The AndroidManifest.xml File documentation.

有关于更多地为你的应用怎样构成manifest文件,查看AndroidManifest.xml文件文档。



Declaring component capabilities(声明组件功能)


As discussed above, in Activating Components, you can use an Intent to start activities, services, and broadcast receivers. You can do so by explicitly naming the target component (using the component class name) in the intent. However, the real power of intents lies in the concept of implicit intents. An implicit intent simply describes the type of action to perform (and, optionally, the data upon which you’d like to perform the action) and allows the system to find a component on the device that can perform the action and start it. If there are multiple components that can perform the action described by the intent, then the user selects which one to use.

像以上考论Activating Components一样,你可以使用一个Intent去启动activitied,services,和broadcast receivers。你通过在Intent明确地命名一个目标组件(使用组件类名)来启动。然而,Intent实际的能力在于隐式Intent的概念。一个隐式的intent简单地描述了要执行动作类型(也可以在intent之上要执行动作的数据)和允许系统在设备上查找一个组件,可以执行动作和启动它。如果有多个组件通过Intent描述要执行,那么用户可以选择一个去使用。



The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest file of other apps on the device.

系统识别能响应intent的components的方法是,将接收到的intent与设备上其它app的manifest文件中提供的intent过滤器作比较。



When you declare an activity in your app's manifest, you can optionally include intent filters that declare the capabilities of the activity so it can respond to intents from other apps. You can declare an intent filter for your component by adding an <intent-filter> element as a child of the component's declar`ation element.

当在你的应用manifest文件中声明一个activity时,你会随意地包含intent filters声明activity兼容性以便它会响应来自其它应用的intent。你可以为你的component声明一个intent过滤器,方法是在声明component标签的子标签处添加<intent-filter>。



For example, if you've built an email app with an activity for composing a new email, you can declare an intent filter to respond to "send" intents (in order to send a new email) like this:

例如,如果你有一个已经建立的email应用,这个应用有一个写邮件的acitivity,你会声明一个intent filter去响应"发送"意图(为了发送一新的邮件)像这样:





Then, if another app creates an intent with the ACTION_SEND action and pass it to startActivity(), the system may start your activity so the user can draft and send an email.

然后,如果其它应用创建一个intent和ACTION_SEND动作并且通过它去执行startActivity()方法,系统会启动你的activity,用户可以指定和发送一封邮件。



For more about creating intent filters, see the Intents and Intent Filters document.

关于创建intent filters更多的信息,查看Intents和Intent Filters文档。






Declaring app requirements(声明应用需求)


There are a variety of devices powered by Android and not all of them provide the same features and capabilities. In order to prevent your app from being installed on devices that lack features needed by your app, it's important that you clearly define a profile for the types of devices your app supports by declaring device and software requirements in your manifest file. Most of these declarations are informational only and the system does not read them, but external services such as Google Play do read them in order to provide filtering for users when they search for apps from their device.

有很多通过安装了Android系统的设备并不是提供同样的特性和兼容性。为了防止你的应用需要安装到设备上缺乏你的应用需要的特性 。在你的manifest文件中明确声明你的应用支持设备的类型和软件所需要的设备非常重要。大部分这些声明是只是信息并且系统不会去阅读他们,但是外面的服务例如Google Play会去阅读他们,为了用户搜索他们设备上的应用时提供过滤器。



For example, if your app requires a camera and uses APIs introduced in Android 2.1 (API Level 7), you should declare these as requirements in your manifest file like this:

例如,如果你的应用需要一个照相机和在使用在Android2.1引入用户使用的APIS,你应该在你的manifest文件中声明这些所需要的像这样:









Now, devices that do not have a camera and have an Android version lower than 2.1 cannot install your app from Google Play.

现在,设备没有照相机并且有一个低于Android2.1版本的设备不能从Google Play安装你的应用。


However, you can also declare that your app uses the camera, but does not require it. In that case, your app must set the required attribute to "false" and check at runtime whether the device has a camera and disable any camera features as appropriate.

然而,你同样可以在你的应用声明使用camera,但是不需要它。在这种情况下,你必须必须设置required属性为"false",不是在运行时检查是否有相机,而是检查是否有适当的相机特性。



More information about how you can manage your app's compatibility with different devices is provided in the Device Compatibility document.

有关于你可以管理在你的应用怎样兼容不同设备的更多信息是在设备上提供Compatibility文档。




App Resources(应用资源)


An Android app is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual presentation of the app. For example, you should define animations, menus, styles, colors, and the layout of activity user interfaces with XML files. Using app resources makes it easy to update various characteristics of your app without modifying code and—by providing sets of alternative resources—enables you to optimize your app for a variety of device configurations (such as different languages and screen sizes).

一个android应用不仅仅是由代码组成--它需要从源代码分开的资源,例如图片,音频文件,和任何有关应用视觉呈现的东西。例如,你应该定义动画,菜单,样式,颜色,和activity用户界面一些XM文件布局。使用app资源使得你的应用更加容易更新多种特征和修改代码--通过提供设置一些不寻常资源--能使你应用匹配多种设备(例如不同的语言和屏幕大小)。



For every resource that you include in your Android project, the SDK build tools define a unique integer ID, which you can use to reference the resource from your app code or from other resources defined in XML. For example, if your app contains an image file named logo.png (saved in the res/drawable/ directory), the SDK tools generate a resource ID named R.drawable.logo, which you can use to reference the image and insert it in your user interface.

为你的Android项目包含的每一个资源,SDK builde工具定义了一个唯一整型ID,你会在你的应用代码中使用资源引用或者其它资源定义在XML。例如,如果你的应用包含一个名为logo.png照片文件(保存在res/drawable/目录)。SDK工具形成一个叫R.drawable.log的资源ID,你可以使用这个image引用并且在你界面插入它。



One of the most important aspects of providing resources separate from your source code is the ability for you to provide alternative resources for different device configurations. For example, by defining UI strings in XML, you can translate the strings into other languages and save those strings in separate files. Then, based on a language qualifier that you append to the resource directory's name (such as res/values-fr/ for French string values) and the user's language setting, the Android system applies the appropriate language strings to your UI.

提供资源从你的资源代码分离出来的多个重要方面是为你提供特殊的资源配置不同的设备。例如,通过在XML定义UI字符串,你可以把字符串翻译成其它语言并且在分开的文件保存那些strings。然后,基于语言合格者,你追加到资源目录名称(例如像res/values-fr一样,法语string值)和用户语言的设定,Android系统应用为你UI的匹配合适的语言strings。 



Android supports many different qualifiers for your alternative resources. The qualifier is a short string that you include in the name of your resource directories in order to define the device configuration for which those resources should be used. As another example, you should often create different layouts for your activities, depending on the device's screen orientation and size. For example, when the device screen is in portrait orientation (tall), you might want a layout with buttons to be vertical, but when the screen is in landscape orientation (wide), the buttons should be aligned horizontally. To change the layout depending on the orientation, you can define two different layouts and apply the appropriate qualifier to each layout's directory name. Then, the system automatically applies the appropriate layout depending on the current device orientation.

Android支持许多不同限定符为你的特殊资源。这个限定符是一个短的字符串,你包括在你的资源目录,为了定义设备配置哪些资源应该被使用。

另一个例子,你应该在你activitites经常创建不通的layout,依赖于设备的屏幕方向和大小。例如,当设备屏幕是在竖直位置(高)时,你可能想要一个被竖直的按钮布局,但是当屏幕在横向位置(宽)时,这个按钮赢水平对齐。去改变依赖于方向的布局,你会定义来两个不同的布局和应用每个布局目录名称恰当的限定符。然后,系统依赖于当前设备的方向会自动应用合适的布局。


For more about the different kinds of resources you can include in your application and how to create alternative resources for different device configurations, read Providing Resources.

有关于在你的应用你会包括不同的类型资源和怎样为不同的设备配置创建特殊的资源,阅读Providing Resources。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值