`

【翻译】(36)布局资源

 
阅读更多

【翻译】(36)布局资源

 

see

http://developer.android.com/guide/topics/resources/layout-resource.html

 

原文见

http://developer.android.com/guide/topics/resources/layout-resource.html

 

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

 

Layout Resource

 

布局资源

 

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

 

See also

 

另见

 

XML Layouts XML布局

 

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

 

A layout resource defines the architecture for the UI in an Activity or a component of a UI.

 

一个布局资源为一个Activity中的用户界面或用户界面的一个组件定义结构。

 

* file location:

 

* 文件位置:

 

res/layout/filename.xml

 

res/layout/<文件名>.xml

 

The filename will be used as the resource ID.

 

文件名将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to a View (or subclass) resource.

 

指向一个View(或子类)资源的资源指针。

 

* resource reference:

 

* 资源引用:

 

In Java: R.layout.filename

 

在Java中: R.layout.<文件名>

 

In XML: @[package:]layout/filename

 

在XML中:@[<包名>:]layout/<文件名>

 

* syntax:

 

* 语法:

 

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

 

<?xml version="1.0" encoding="utf-8"?>

<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@[+][package:]id/resource_name"

    android:layout_height=["dimension" | "fill_parent" | "wrap_content"]

    android:layout_width=["dimension" | "fill_parent" | "wrap_content"]

    [ViewGroup-specific attributes] >

    <View

        android:id="@[+][package:]id/resource_name"

        android:layout_height=["dimension" | "fill_parent" | "wrap_content"]

        android:layout_width=["dimension" | "fill_parent" | "wrap_content"]

        [View-specific attributes] >

        <requestFocus/>

    </View>

    <ViewGroup >

        <View />

    </ViewGroup>

    <include layout="@layout/layout_resource"/>

</ViewGroup>

 

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

 

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

 

Note: The root element can be either a ViewGroup, a View, or a <merge> element, but there must be only one root element and it must contain the xmlns:android attribute with the android namespace as shown.

 

注意:根元素可以是一个ViewGroup,一个View,或一个<merge>元素,但必须仅有一个根元素,并且它必须包含带有android名字空间的xmlns:android元素,如同所示那样。

 

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

 

* elements:

 

* 元素:

 

* <ViewGroup>

 

A container for other View elements. There are many different kinds of ViewGroup objects and each one lets you specify the layout of the child elements in different ways. Different kinds of ViewGroup objects include LinearLayout, RelativeLayout, and FrameLayout.

 

一个用于其它View元素的容器。有许多不同类型的ViewGroup对象,而每一种让你以不同的方式指定子元素的布局。不同类型的ViewGroup对象包括LinearLayout,RelativeLayout,以及FrameLayout。

 

You should not assume that any derivation of ViewGroup will accept nested Views. Some ViewGroups are implementations of the AdapterView class, which determines its children only from an Adapter.

 

你不应该假设ViewGroup的任意派生类将接受内嵌的View。一些ViewGroups是AdapterView类的实现,它仅从一个Adapter中决定它的子对象。

 

* attributes:

 

* 属性:

 

* android:id

 

Resource ID. A unique resource name for the element, which you can use to obtain a reference to the ViewGroup from your application. See more about the value for android:id below.

 

资源ID。元素的唯一资源名称,你可以使用它从你的应用程序中取得指向ViewGroup的引用。见下面更多关于android:id的值的信息。

 

* android:layout_height

 

Dimension or keyword. Required. The height for the group, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

 

尺寸或关键词。必需的。组的高度,作为一个尺寸值(或尺寸资源)或一个关键词("fill_parent"或"wrap_content")。参见下面的可用值。

 

* android:layout_width

 

Dimension or keyword. Required. The width for the group, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

 

尺寸或关键词。必需的。组的宽度,作为一个尺寸值(或尺寸资源)或一个关键词("fill_parent"或"wrap_content")。参见下面的可用值。

 

More attributes are supported by the ViewGroup base class, and many more are supported by each implementation of ViewGroup. For a reference of all available attributes, see the corresponding reference documentation for the ViewGroup class (for example, the LinearLayout XML attributes).

 

更多属性被ViewGroup基类支持,并且许多更多的属性被ViewGroup的每个实现支持。想获取所有可用属性的参考,请参见相应的ViewGroup类的参考文档(例如,LinearLayout的XML属性)。

 

* <View>

 

An individual UI component, generally referred to as a "widget". Different kinds of View objects include TextView, Button, and CheckBox.

 

一个单独的用户界面组件,通常被引用作为一个“部件”。不同类型的View对象包括TextView,Button,以及CheckBox。

 

* attributes:

 

* 属性:

 

* android:id

 

Resource ID. A unique resource name for the element, which you can use to obtain a reference to the View from your application. See more about the value for android:id below.

 

资源ID。元素的唯一资源名称,你可以从你的应用程序中使用它取得指向该View的引用。关于android:id的值的更多信息见下。

 

* android:layout_height

 

Dimension or keyword. Required. The height for the element, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

 

尺寸或关键词。必需的。元素的高度,作为一个尺寸值(或尺寸资源)或一个关键词("fill_parent"或"wrap_content")。可用值见下。

 

* android:layout_width

 

Dimension or keyword. Required. The width for the element, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

 

尺寸或关键词。必需的。元素的宽度,作为一个尺寸值(或尺寸资源)或一个关键词("fill_parent"或"wrap_content")。可用值见下。

 

More attributes are supported by the View base class, and many more are supported by each implementation of View. Read XML Layouts for more information. For a reference of all available attributes, see the corresponding reference documentation (for example, the TextView XML attributes).

 

更多属性被View基类支持,而且许多更多的属性被View的各种实现支持。阅读XML布局以获取更多信息。对于所有可用属性的参考文档,参见相应的参考文档(例如,TextView的XML属性)。

 

* <requestFocus>

 

Any element representing a View object can include this empty element, which gives it's parent initial focus on the screen. You can have only one of these elements per file.

 

任意代表一个View对象的元素可以包含这个空元素,它给它的父元素屏幕的最初焦点。每个文件你只可以有一个这样的元素。

 

* <include>

 

Includes a layout file into this layout.

 

包含一个布局文件进这个布局。

 

* attributes:

 

* 属性:

 

* layout

 

Layout resource. Required. Reference to a layout resource.

 

布局资源。必需的。指向一个布局资源的引用。

 

* android:id

 

Resource ID. Overrides the ID given to the root view in the included layout.

 

资源ID。覆盖在被包含的布局中赋给根视图的ID。

 

* android:layout_height

 

Dimension or keyword. Overrides the height given to the root view in the included layout. Only effective if android:layout_width is also declared.

 

尺寸或关键词。覆盖在被包含布局中被赋给根视图的高度。仅当android:layout_width也被声明时才有效。

 

* android:layout_width

 

Dimension or keyword. Overrides the width given to the root view in the included layout. Only effective if android:layout_height is also declared.

 

尺寸或关键词。覆盖在被包含布局中被赋给根视图的宽度。仅当android:layout_height也被声明时才有效。

 

You can include any other layout attributes in the <include> that are supported by the root element in the included layout and they will override those defined in the root element.

 

你可以在<include>中包含其它任意在被包含的布局中的根元素支持的布局属性,而它们将覆盖在根元素中定义的那些属性。

 

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

 

Caution: If you want to override the layout dimensions, you must override both android:layout_height and android:layout_width—you cannot override only the height or only the width. If you override only one, it will not take effect. (Other layout properties, such as weight, are still inherited from the source layout.)

 

警告:如果你希望覆盖布局尺寸,你必须同时覆盖android:layout_height和android:layout_width——你不能只覆盖高度或只覆盖宽度。如果你只覆盖一个,它将没有效果。(其它布局属性,诸如权重,仍然从源布局中继承。)

 

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

 

Another way to include a layout is to use ViewStub. It is a lightweight View that consumes no layout space until you explicitly inflate it, at which point, it includes a layout file defined by its android:layout attribute. For more information about using ViewStub, read Layout Tricks: ViewStubs.

 

另一种包含一个布局的方式是使用ViewStub。它是一个轻量级View,它不消耗布局空间,直至你显式地解压它,那时候,它包含它的android:layout属性定义的布局文件。关于使用ViewStub的更多信息,请阅读《布局技巧:ViewStub》

 

* <merge>

 

An alternative root element that is not drawn in the layout hierarchy. Using this as the root element is useful when you know that this layout will be placed into a layout that already contains the appropriate parent View to contain the children of the <merge> element. This is particularly useful when you plan to include this layout in another layout file using <include> and this layout doesn't require a different ViewGroup container. For more information about merging layouts, read Layout Tricks: Merging.

 

一个可选的根元素,它不在布局层级中被绘画。当你知道这个布局将被放置进一个已经包含合适父View的布局以容纳<merge>元素的子元素时,使用它作为根元素是有用的。它特别有用,当你计划使用<include>包含这个布局在另一个布局文件中,而这个布局不需要一个不同的ViewGroup容器时。想获取关于合并布局的更多信息,请阅读《布局技巧:合并》。

 

Value for android:id

 

用于android:id的值

 

For the ID value, you should usually use this syntax form: "@+id/name". The plus symbol, +, indicates that this is a new resource ID and the aapt tool will create a new resource integer in the R.java class, if it doesn't already exist. For example:

 

对于ID的值,你通常应该使用这个语法形式:"@+id/<名称>"。加号,"+",指示这是一个新的资源ID,而aapt工具将在R.java类中创建一个新的资源整型,如果它还不曾存在。例如:

 

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

 

<TextView android:id="@+id/nameTextbox"/>

 

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

 

The nameTextbox name is now a resource ID attached to this element. You can then refer to the TextView to which the ID is associated in Java:

 

nameTextbox的名称现在是一个依附到这个元素的资源ID。然后你可以引用该ID在Java中关联的TextView:

 

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

 

findViewById(R.id.nameTextbox);

 

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

 

This code returns the TextView object.

 

这段代码返回TextView对象。

 

However, if you have already defined an ID resource (and it is not already used), then you can apply that ID to a View element by excluding the plus symbol in the android:id value.

 

然而,如果你已经定义一个ID资源(并且它还未使用),那么你可以通过在android:id值中不包括加号来应用那个ID到一个View元素。

 

Value for android:layout_height and android:layout_width:

 

用于android:layout_height和android:layout_width的值:

 

The height and width value can be expressed using any of the dimension units supported by Android (px, dp, sp, pt, in, mm) or with the following keywords:

 

高度和宽度值可以使用Android支持的任意尺寸单位来表达(px,dp,sp,pt,in,mm)或使用以下关键词:(注:猜测这些单位的含义——px是指pixel像素,dp是指density-independent pixel密度无关像素,sp是指scale-independent pixels伸缩无关像素,pt是指point点,in是指inch英寸,mm是指millimeter毫米。详见http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android)

 

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

 

* Value Description

 

* 值 描述

 

* match_parent Sets the dimension to match that of the parent element. Added in API Level 8 to deprecate fill_parent.

 

* match_parent 设置尺寸以匹配父元素的尺寸。在API级别8中新增以废弃fill_parent。

 

* fill_parent Sets the dimension to match that of the parent element.

 

* fill_parent 设置尺寸以匹配父元素的尺寸。

 

* wrap_content Sets the dimension only to the size required to fit the content of this element.

 

* wrap_content 设置尺寸仅为适应这个元素的内容所需的大小。

 

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

 

Custom View elements

 

自定义视图元素

 

You can create your own custom View and ViewGroup elements and apply them to your layout the same as a standard layout element. You can also specify the attributes supported in the XML element. To learn more, see the Custom Components developer guide.

 

你可以创建你自己的自定义View和ViewGroup元素并且应用它们到你的布局,和一个标准布局元素相同。你还可以指定在XML元素中支持的属性。要学习更多,参见自定义组件开发者指引。

 

* example:

 

* 示例:

 

XML file saved at res/layout/main_activity.xml:

 

保存为res/layout/main_activity.xml的XML文件:

 

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

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

              android:layout_width="fill_parent" 

              android:layout_height="fill_parent" 

              android:orientation="vertical" >

    <TextView android:id="@+id/text"

              android:layout_width="wrap_content"

              android:layout_height="wrap_content"

              android:text="Hello, I am a TextView" />

    <Button android:id="@+id/button"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="Hello, I am a Button" />

</LinearLayout>

 

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

 

This application code will load the layout for an Activity, in the onCreate() method:

 

这段应用程序代码将在onCreate()方法中为一个Activity加载该布局:

 

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

 

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView.(R.layout.main_activity);

}

 

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

 

* see also:

 

* 另见:

 

* XML Layouts XML布局

* View 视图

* ViewGroup 视图组

 

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 - 13 Jan 2012 0:46

 

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

 

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/


分享到:
评论

相关推荐

    winrar 中文翻译资源文件

    winrar.rc是WinRAR的主要资源文件,其中包含了软件界面的所有元素的定义,包括窗口布局、按钮、菜单项、对话框等。中文翻译资源文件就是对这部分内容进行了汉化处理,将原本的英文资源替换为中文,确保用户在使用时...

    Asp.net 资源文件翻译助手 exe

    Asp.NET资源文件翻译助手是一款专为Asp.NET开发者设计的实用工具,旨在简化应用程序本地化过程中的资源文件翻译工作。资源文件在Asp.NET中扮演着关键角色,它们存储了应用程序中的字符串、错误消息和其他可本地化...

    apk反翻译生成资源文件

    3. **修改资源**:如果你需要修改资源,如翻译字符串或调整界面布局,现在你可以直接编辑这些文本文件。 4. **重新构建APK**:完成修改后,使用Apktool重新打包APK,命令如下: ``` apktool b ``` 这将生成一...

    Flutter官方文档详细翻译

    3. **构建布局**:"05 Flutter中构建布局.pdf"涵盖了Flutter中的各种布局Widget,如Row、Column、Flex、Stack、Grid等,这些Widget可以帮助你创建复杂的屏幕设计,适应不同屏幕尺寸。 4. **创建应用程序**:"03 ...

    js谷歌翻译插件.rar

    CSS文件则用于美化和布局插件的视觉效果,使得翻译功能能够无缝地融入到网页中。 在实际应用中,开发者需要遵循压缩包内的HTML示例,将相关JS脚本引入到自己的项目中。这些脚本可能包括初始化翻译接口、处理用户...

    美团云 AI 布局.pdf

    再次,美团云的AI布局涉及到多个应用场景,包括智能客服、智慧交通、活体监测、证件识别、智能录入、机器翻译、智慧金融、智慧政务、平安城市和智慧法庭等。这些应用场景表明了美团云致力于将AI技术融入到各个行业,...

    AUTOCAD翻译软件

    5. **保留原始格式**:翻译后的文本会替换原文本,但保留原有的布局和格式,确保图纸的可读性和专业性。 6. **兼容性**:与不同版本的AUTOCAD软件兼容,适应用户的不同需求。 7. **用户界面**:直观易用的界面,使得...

    自己制作在线翻译html

    最后,`static`文件夹可能包含CSS样式表、图片和其他静态资源。在HTML文件中通过`&lt;link&gt;`标签引用CSS文件,可以实现样式分离,提高代码可维护性。 总结起来,创建一个自定义的在线翻译HTML页面需要掌握HTML基本结构...

    Android :布局与国际化

    在Android应用开发中,布局(Layout)是构建用户界面(UI)的基础,它定义了屏幕上...通过选择适当的布局类型、编写多语言资源文件以及理解Android系统如何处理这些资源,开发者可以构建出适应全球用户的高质量应用。

    ResxTranslator(一个基于GOOGLE API , C#的RES翻译软件)

    ResxTranslator简化了资源翻译环节,但完整的本地化流程还需要考虑到其他因素,如UI布局调整、测试和验证等。 6. 性能和优化: 谷歌翻译API可能会有调用次数和费用限制,ResxTranslator可能需要优化请求频率,避免...

    一款翻译软件源码

    标题中的“一款翻译软件源码”表明我们讨论的是一个用于翻译的应用程序的源代码,而这个应用程序是针对Android平台设计的。源码是开发者用来理解、...无论是对初学者还是经验丰富的开发者来说,都是一份有价值的资源。

    Android中实现文字、图片资源国际化案例

    这个过程涉及到将应用中的文本和图片资源分离出来,以便根据不同地区创建对应的翻译版本。下面我们将深入探讨如何在Android中实现文字和图片资源的国际化。 首先,我们需要理解Android的资源管理系统。Android使用...

    ExtJS4官方指南翻译:DragandDrop拖放/Grid组件/Tree组件/容器与布局

    在"ExtJS4官方指南翻译:DragandDrop拖放/Grid组件/Tree组件/容器与布局"中,我们将会探讨以下几个核心概念: 1. **Drag and Drop(拖放)**: ExtJS4提供了完善的拖放支持,允许用户通过鼠标操作在界面上移动元素...

    翻译翻译什么是HTML5(二)配套资源

    通过这些资源,你可以实践HTML5的新标签使用,学习如何创建响应式布局,或者探索如何利用HTML5的多媒体和离线存储功能来提升你的Web应用。 总的来说,HTML5是现代Web开发的基石,它的出现推动了Web技术的发展,使得...

    DIV+CSS布局大全

    《DIV+CSS布局大全》是针对现代网页设计与制作的一项核心技术进行深度解析的资源集合。在当前互联网环境中,DIV+CSS布局已经成为了构建高效、优化的网站不可或缺的一部分。这种布局方式以其灵活性、可维护性和对搜索...

    exe 图标资源提取工具

    本地化团队可以提取并翻译字符串资源,以适应不同语言环境;而UI设计师则可以利用它来快速调整和测试图标设计。 总之,“Resource Hacker”作为一个强大的图标资源提取工具,为开发者和设计师提供了便捷、高效的...

    unity 界面菜单翻译

    "unity 界面菜单翻译"正是为了解决这个问题,提供了中文翻译,帮助用户更好地理解和操作Unity。 Unity的界面主要包括以下几个核心部分: 1. **主菜单(Main Menu)**:这是Unity启动后首先看到的菜单,包含了...

    Android 资源与应用国际化

    - **用户的布局资源**:用户自定义的布局文件。 - **风格和主题(Styles and Themes)**:定义应用的整体外观和感觉。 **资产(Assets)**则是指那些不经过编译处理的原始文件,一般放在`assets`目录下。资产文件可以是...

    C#翻译软件源码 C#

    9. **资源管理**:如果软件支持多种语言,那么会涉及到资源文件的管理,例如.resx文件用于存储不同语言的字符串资源。 10. **状态管理**:翻译软件可能需要保存用户的设置和历史记录,这涉及到状态管理,可能用到...

Global site tag (gtag.js) - Google Analytics