【Android 开发教程】LinearLayout线性布局
来源:互联网 发布:午夜视频聊天软件 编辑:程序博客网 时间:2024/05/21 09:05
本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/LinearLayout把视图组织成一行或一列。子视图能被安排成垂直的或水平的。想知道LinearLayout是如何工作的,首先考虑一下典型的mail.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:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- </LinearLayout>
每一个View和ViewGroup有一些共同的属性,一些例子:
属性描述layout_width指定View或ViewGroup的宽度layout_height指定View或ViewGroup的高度layout_marginTop指定View或ViewGroup上方的额外空间layout_marginBottom指定View或ViewGroup下方的额外空间layout_marginLeft指定View或ViewGroup左侧的额外空间layout_marginRight指定View或ViewGroup右侧的额外空间layout_gravity指定View或ViewGroup中的子视图的排列位置layout_weight指定指派给View或ViewGroup的额外空间尺寸layout_x指定View或ViewGroup的x坐标layout_y指定View或ViewGroup的y坐标举个例子,<TextView>元素使用了fill_parent常量,所以的宽度填充了整个它所在布局的宽度。它的高度被设置成wrap_content常量,这意味着,它的高度将和它所在的布局一样。如果不想<TextView>占据整个屏幕,可以把layoutt_width元素设置成wrap_content,就像这样:
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello" /><span style="font-family:Arial,Helvetica,sans-serif;">
- </span>
以上的代码,把TextView的宽度设置成和它所包含的文本的长度一样。
请看如下的布局:
- <?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:layout_width="100dp"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- <Button
- android:layout_width="160dp"
- android:layout_height="wrap_content"
- android:text="Button" />
- </LinearLayout>
- 【Android 开发教程】LinearLayout线性布局
- Android开发之线性布局(LinearLayout)
- Android 线性布局:LinearLayout
- Android:线性布局LinearLayout
- Android-LinearLayout线性布局
- Android LinearLayout 线性布局
- Android 布局LinearLayout(线性布局)
- 【Android开发学习23】界面布局之线性布局LinearLayout
- Android--LinearLayout(线性布局)
- android线性布局LinearLayout源代码
- Android初试--LinearLayout(线性布局)
- Android线性布局管理器LinearLayout
- Android UI LinearLayout线性布局
- Android之LinearLayout线性布局
- Android LinearLayout(线性布局)
- Android笔记---LinearLayout线性布局
- Android-线性布局(LinearLayout)
- Android LinearLayout线性布局属性
- C/C++中内联汇编
- liunx ubuntu下 Eclipse卸载ADT的方法
- utunbu安装7z解压工具
- 浅谈android线程的优先级
- float C#数据类型
- 【Android 开发教程】LinearLayout线性布局
- HTTP协议详解
- 使用asp.net模板生成html静态页面的五种方案
- Tiny6410 ——LED 驱动程序设计
- UML类图关系大全
- 【并查集】小胖的奇偶
- 4.0源码编译问题
- 数据结构之Hash算法
- 由ibatis分页想到的