Android 开发指南 翻译2 User Interface:XML Layouts
来源:互联网 发布:零速争霸玩具淘宝 编辑:程序博客网 时间:2024/06/01 10:41
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.
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 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.
android:id="@+id/my_button"@引导符
+ 增加一个id
使用Android框架的id
android:id="@android:id/empty"
Layout Parameters
XML layout attributes named layout_something
define 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对宽高值。
getMeasuredWidth()
and getMeasuredHeight()
.getWidth()
and getHeight()
.- Android 开发指南 翻译2 User Interface:XML Layouts
- Android 开发指南 翻译 User Interface -- Dialogs
- Android 开发指南翻译开篇--User Interface -Styles and Themes
- Android 开发指南 翻译3:User Interface: Input Events
- Dev Guide/Framework Topics/User Interface/XML Layouts
- Android 开发指南 翻译 User Interfaces -- Action Bar
- [Android SDK 翻译] User Interface Guidelines
- User Interface(UI)之Layouts学习
- API-user Interface翻译
- XML User Interface Language
- Android - User Interface
- 读书笔记[Android Beginning 2] chapter 4 Using XML-Based Layouts
- Android XML布局详解 - XML Layouts
- Android Interface Definition Language (AIDL) android接口定义语言 开发文档翻译 - 2
- Android Interface Definition Language (AIDL) android接口定义语言 开发文档翻译 - 2
- Android官方文档翻译 五 1.3Building a Simple User Interface
- XML Layouts
- Android SDK开发指南(翻译)系列:引言
- Response.ContentType 详细列表
- 引导孩子画画
- 网页异常分析报告
- dd
- 如何在vs2008里集成AjaxControlToolkit
- Android 开发指南 翻译2 User Interface:XML Layouts
- Qt状态机框架的一个典型应用
- 使用Win32 API实现限制编辑框输入的功能
- UI 动画特效及效率探讨
- Android类库
- 机房收费系统总结
- Android运行时
- 在网页上Run Code (测试代码) 功能
- 学习jsp第三天