Linear Layout 布局技巧
来源:互联网 发布:淘宝店铺出租平台 编辑:程序博客网 时间:2024/04/25 20:42
技巧:要创建一个每个子View在屏幕上都有相同空间的线性布局,对于垂直布局,要把每个子View的android:layout_height属性值都设置为”0dp”,对于与水平布局,要把每个子View的android:layout_width的属性值都设置为”0dp”。然后把每个子View的android:layout_weight属性值都设置为”1”。
Layout Weight
Equally weighted children
To create a linear layout in which each child uses the same amount of space on the screen, set theandroid:layout_height
of each view to "0dp"
(for a vertical layout) or the android:layout_width
of each view to "0dp"
(for a horizontal layout). Then set theandroid:layout_weight
of each view to "1"
.
LinearLayout
also supports assigning a weight to individual children with the android:layout_weight
attribute. This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
For example, if there are three text fields and two of them declare a weight of 1, while the other is given no weight, the third text field without weight will not grow and will only occupy the area required by its content. The other two will expand equally to fill the space remaining after all three fields are measured. If the third field is then given a weight of 2 (instead of 0), then it is now declared more important than both the others, so it gets half the total remaining space, while the first two share the rest equally.
android:layout_gravity
Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.
Must be one or more (separated by '|') of the following constant values.
top
0x30Push object to the top of its container, not changing its size.bottom
0x50Push object to the bottom of its container, not changing its size.left
0x03Push object to the left of its container, not changing its size.right
0x05Push object to the right of its container, not changing its size.center_vertical
0x10Place object in the vertical center of its container, not changing its size.fill_vertical
0x70Grow the vertical size of the object if needed so it completely fills its container.center_horizontal
0x01Place object in the horizontal center of its container, not changing its size.fill_horizontal
0x07Grow the horizontal size of the object if needed so it completely fills its container.center
0x11Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.fill
0x77Grow the horizontal and vertical size of the object if needed so it completely fills its container.clip_vertical
0x80Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.clip_horizontal
0x08Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.start
0x00800003Push object to the beginning of its container, not changing its size.end
0x00800005Push object to the end of its container, not changing its size.This corresponds to the global attribute resource symbol layout_gravity
.
- Linear Layout 布局技巧
- 线性布局 Linear Layout
- Linear Layout(线性布局)
- Linear Layout(线形布局)
- Android线性布局(Linear Layout)
- Android线性布局(Linear Layout)
- Android布局---线性布局(Linear Layout)
- 布局(线性布局 Linear Layout )相对布局 (Relative Layout)
- Android布局之一——Linear Layout
- Linear Layout
- Linear Layout
- Linear Layout
- Android开发教程 --- 布局(线性布局 Linear Layout )(相对布局 Relative Layout)
- Android UI Design 03 : 线性布局 Linear Layout
- 尝试式android自学教程-linear layout(线性布局)
- Linear Layout,Relative Layout
- Layout--Linear与Relative
- Layout---Linear Layout和Relative Layout
- VBA 读写文本文件的几种方法
- 用数据管理过程(3)——可预测级别的量化管理(麦当劳的管理方式)
- shell sed过滤器详解
- android事件传递机制,以及ondispatchEvent()、onInterceptTouchEvent()和OnTouchEvent()三个方法的作用关系
- Internet Explorer 11 的变化
- Linear Layout 布局技巧
- IO完成端口
- Android外部jar包相关问题
- Python解决codeforces ---- 6
- ASM总结---未整理
- js相除出现浮点(JS浮点计算BUG屏蔽)
- Visual Studio 2010 UML 朔模功能初步概述
- 关于VC中生成的PE(exe, dll, sys...)文件中对函数名称的修饰
- $! ,$?, $$,$@在shell中代表什么