Linear Layout
来源:互联网 发布:部落冲突亡灵升级数据 编辑:程序博客网 时间:2024/04/20 04:41
Linear Layout
linear layout是一种view group,它以一个单一的方向(垂直或者是水平)排列它所有的子控件,你可以用android:orientation属性来指定布局方向。
linear layout所有的子控件都是一个个的堆叠在上一个子控件之后,所以如果一个linearlayout的方向是垂直的,那么在每一行只能有一个子控件,不管该控件有多宽。
Layout Weight
linear layout 可以通过android:layout_weight属性给每一个子控件分配一个weight。这个属性确定了每个子控件应该占据多少的屏幕空间。最大可以占据整个父控件所有的空间。父控件中的空间以子控件中声明的weight值的比例分配给子控件。默认的weight值是0。
例如:当三个button控件中的两个控件都声明了weight为1,另一个button没有给weight值,那么这个没有给定weight值的button控件就不会扩展,只是占据规定的位置,这两个给定weight值的控件就会扩展到完全占据剩余的空间。如果此时没有给定weight值的那个控件给定weight值是2,那么这三个button就按照1:1:2的比例来瓜分真个布局空间。
Example
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/to" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/subject" /> <EditText android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="top" android:hint="@string/message" /> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/send" /></LinearLayout>
下面是是效果图:
0 0
- Linear Layout
- Linear Layout
- Linear Layout
- Linear Layout,Relative Layout
- 线性布局 Linear Layout
- Layout--Linear与Relative
- Linear Layout 布局技巧
- Layout---Linear Layout和Relative Layout
- Linear Layout(线性布局)
- Android: Linear Layout and weight
- Linear Layout(线形布局)
- Android线性布局(Linear Layout)
- Android API Guides---Linear Layout
- Android线性布局(Linear Layout)
- RecyclerView机制解析: Linear Layout
- Android布局之一——Linear Layout
- Android UI学习 - Linear Layout, RelativeLayout
- Android开发笔记之Linear Layout
- 如何学习android(看stay4it的笔记)+android stdio简单实用简介
- Oracle 执行计划优化
- AngularJs+bootstrap搭载前台框架2
- ThinkPHP中的行为扩展和插件详解
- linux IIC子系统分析(六)——I2c plaform driver 初始化
- Linear Layout
- 解决AngularJS使用ng-bind-html会过滤html中style属性的问题
- Ubuntu 14.04 安装xvid编码器
- 关于arcgis 9.3 Java服务器发布服务问题
- <LeetCode OJ> 357. Count Numbers with Unique Digits
- 单链表的增、删、查、改、逆置、排序
- restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-
- 图片压缩工具Thumbnailator的使用
- AngularJs+bootstrap搭载前台框架3