Android 开发指南 翻译2 User Interface:XML Layouts
2012-02-04 15:01
531 查看
Android 开发指南翻译2 User Interface:XML Layouts
定义:Your layout is the architecture for the user interface in an Activity. It defines
the layout structure and holds all the elements that appear to the user.
定义:layout是在Activity中的用户界面结构。包括:结构和元素。
声明的方法:
>在xml文件中定义UI元素
>在程序运行时,实例化layout元素
两种方法可以交替使用。
The advantage to declaring your UI in XML is that it enables you to better separate the presentation
of your application from the code that controls its behavior.
保存路径 res/layout下。
文件main_layout.xml布局文件载入。
Some attributes are specific to a View object,And, other attributes
are considered "layout parameters," which are attributes that describe certain layout orientations of the View object, as defined by that object's parent ViewGroup object.
两种属性:
>View类属性:该View的属性。
>布局属性:描述视图的布局方向。
ID:Any View object
may have an integer ID associated with it, to uniquely identify the View within the tree.
@引导符
+ 增加一个id
使用Android框架的id
Layout Parameters
XML layout attributes named
for the View that are appropriate for the ViewGroup in which it resides.
LayoutParams are used by views to tell their parents how they
want to be laid out.
Layout 参数:属性layout_XXXX是定义View在ViewGroup
的适当位置。View的使用这些属性用来告诉他们的父对象,他们想如何摆放。
layout_width,layout_height他们的值可以是:固定值dip,dp,px;wrap_content;fill_parent
Layout Position
view是以矩形区域,通过getLeft(),getTop(),getRight(),getBottom()获取相对于父对象的位置,单位是px。
The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.
View拥有2对宽高值。
The
first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent. The measured dimensions can be obtained by calling
>第一对儿:测量宽高:定义在父对象中的大小。
The
second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout.The
width and height can be obtained by calling
>第二对儿:绘制宽高:定制实际绘制的大小。
Padding
can be used to offset the content of the view by a specific amount of pixels.
Padding是View内容与View的边界。(区别于Margin:是view和其他view的边界。)
定义:Your layout is the architecture for the user interface in an Activity. It defines
the layout structure and holds all the elements that appear to the user.
定义:layout是在Activity中的用户界面结构。包括:结构和元素。
声明的方法:
>在xml文件中定义UI元素
>在程序运行时,实例化layout元素
两种方法可以交替使用。
The advantage to declaring your UI in XML is that it enables you to better separate the presentation
of your application from the code that controls its behavior.
Write the 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>
保存路径 res/layout下。
Load the XML Resource
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); }
文件main_layout.xml布局文件载入。
Attributes
Some attributes are specific to a View object,And, other attributesare considered "layout parameters," which are attributes that describe certain layout orientations of the View object, as defined by that object's parent ViewGroup object.
两种属性:
>View类属性:该View的属性。
>布局属性:描述视图的布局方向。
ID:Any View object
may have an integer ID associated with it, to uniquely identify the View within the tree.
android:id="@+id/my_button"
@引导符
+ 增加一个id
使用Android框架的id
android:id="@android:id/empty"
Layout Parameters
XML layout attributes named
layout_somethingdefine layout parameters
for the View that are appropriate for the ViewGroup in which it resides.
LayoutParams are used by views to tell their parents how they
want to be laid out.
Layout 参数:属性layout_XXXX是定义View在ViewGroup
的适当位置。View的使用这些属性用来告诉他们的父对象,他们想如何摆放。
layout_width,layout_height他们的值可以是:固定值dip,dp,px;wrap_content;fill_parent
Layout Position
view是以矩形区域,通过getLeft(),getTop(),getRight(),getBottom()获取相对于父对象的位置,单位是px。
Size, Padding and Margins
The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.View拥有2对宽高值。
The
first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent. The measured dimensions can be obtained by calling
getMeasuredWidth()and
getMeasuredHeight().
>第一对儿:测量宽高:定义在父对象中的大小。
The
second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout.The
width and height can be obtained by calling
getWidth()and
getHeight().
>第二对儿:绘制宽高:定制实际绘制的大小。
Padding
can be used to offset the content of the view by a specific amount of pixels.
Padding是View内容与View的边界。(区别于Margin:是view和其他view的边界。)
相关文章推荐
- Android 开发指南 翻译3:User Interface: Input Events
- Android开发指南中文版(九)User Interface-XML Layouts
- Android 开发指南 翻译 User Interface -- Dialogs
- Android 开发指南翻译开篇--User Interface -Styles and Themes
- Android开发指南中文版(十二)User Interface-Dialogs
- Android帮助文档翻译——开发指南(三)任务和Back Stack
- Android帮助文档翻译——开发指南(一)应用程序基本原理
- Android开发指南中文版(十一)User Interface-Menus
- Android官方开发指南翻译(未整理)
- Android开发指南中文版(十四)User Interface-Binding to Data with AdapterView
- Android官方开发指南翻译(2)-应用程序基本原理
- Android 开发指南 翻译11 Application Resources -- Drawable Resources
- Android 开发指南 翻译7 Application Resources: Handling Runtime Changes(未完...)
- Android帮助文档翻译——开发指南(十五)获取用户位置
- Android 开发指南 翻译 User Interfaces -- Action Bar
- Android帮助文档翻译——开发指南(十五)获取用户位置
- Android 开发指南 翻译11 Application Resources -- String Resources
- Android开发指南中文版(十三)User Interface-Notifications
- NDK官方开发指南翻译之 Android.mk
- Android SDK开发指南(翻译)系列三:Tools(一)--使用AIDL, 设计一个远程接口