Android7.0中文文档 -- GridLayout

完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/GridLayout.html

GridLayout

public class GridLayout
extends ViewGroup

java.lang.Object
   ↳android.view.View
    ↳android.view.ViewGroup
     ↳android.widget.GridLayout


A layout that places its children in a rectangular grid.
将子项放置到一个矩形网格的布局。

The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).

Row and Column Specs
Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells. Although cells do not normally overlap in a GridLayout, GridLayout does not prevent children being defined to occupy the same cell or group of cells. In this case however, there is no guarantee that children will not themselves overlap after the layout operation completes.
Default Cell Assignment
If a child does not specify the row and column indices of the cell it wishes to occupy, GridLayout assigns cell locations automatically using its: orientation, rowCount and columnCount properties.
Space
Space between children may be specified either by using instances of the dedicated Space view or by setting the leftMargin, topMargin, rightMargin and bottomMargin layout parameters. When the useDefaultMargins property is set, default margins around children are automatically allocated based on the prevailing UI style guide for the platform. Each of the margins so defined may be independently overridden by an assignment to the appropriate layout parameter. Default values will generally produce a reasonable spacing between components but values may change between different releases of the platform.
Excess Space Distribution
As of API 21, GridLayout's distribution of excess space accomodates the principle of weight. In the event that no weights are specified, the previous conventions are respected and columns and rows are taken as flexible if their views specify some form of alignment within their groups.
网格由一组无限细的线组成,将可视区域分割为 单元格。在整个API中,网格线被网格 索引引用。 N列的网格有 N + 1个网格索引,包括从 0N。无论如何配置GridLayout,网格索引 0都固定在容器的起始边缘,网格索引 N被固定到它的末尾边缘(在内边距(padding)后面)。
行和列的规范
按照 rowSpeccolumnSpec布局参数的定义,子项占据了一个或多个相邻的单元格。每个Spec都定义了将要被占用的一组行或列;以及如何在生成的单元组中对子项进行对齐。在GridLayout中,虽然单元格通常不会重叠,但GridLayout并不能阻止子项被定义为占用相同的单元格或单元格的组。但是,在这种情况下,不能保证在布局操作完成之后,子项不会有重叠。
默认了单元格的分配
如果一个子项没有指定它想要占用的单元格的行和列索引,GridLayout就会自动使用它的: orientationrowCountcolumnCount属性。
空间
子项之间的空间可以通过使用专用的 Space视图的实例来指定,也可以通过设置 leftMargintopMarginrightMarginbottomMargin布局参数来指定。如果 useDefaultMargins属性被设置,根据平台流行的UI样式指南,围绕子项的默认外边距(margin)会自动分配。定义的每一个外边距(margin)都可以独立地覆盖适当的布局参数。默认值通常会在组件之间产生合理的间隔,但是不同版本平台的值可能会发生变化。
额外空间的分布
API 21版本,GridLayout的空间分布遵循权重原则。在没有指定权重的情况下,则遵循以前的约定,如果视图指定了组内的某种形式的对齐方式,那么列和行就会被认为是灵活的(flexible)。

The flexibility of a view is therefore influenced by its alignment which is, in turn, typically defined by setting the gravity property of the child's layout parameters. If either a weight or alignment were defined along a given axis then the component is taken as flexible in that direction. If no weight or alignment was set, the component is instead assumed to be inflexible.
因此,视图的灵活性受到它的对齐方式的影响,而它的对齐方式通常是通过设置子项布局参数的gravity属性来定义的。如果在指定的轴上定义了一个权重或对齐,则组件在这个方向上被认为是灵活(flexible)的。如果没有设置权重和对其,则组件被认为是不灵活(inflexible)的。

Multiple components in the same row or column group are considered to act in parallel. Such a group is flexible only if all of the components within it are flexible. Row and column groups that sit either side of a common boundary are instead considered to act in series. The composite group made of these two elements is flexible if one of its elements is flexible.
同一行或列组中的多个组件被认为是并行行为。只有在其中的所有组件都是灵活(flexible)的情况下,这样的组才具有灵活性。在公共边界的任意一侧的行和列组被认为是序列行为。如果其中一个元素是灵活的(flexible),那么由这两个元素组成的组合组也是灵活的(flexible)。

To make a column stretch, make sure all of the components inside it define a weight or a gravity. To prevent a column from stretching, ensure that one of the components in the column does not define a weight or a gravity.
要使列拉伸,请确保其中的所有组件都定义了一个权重值或一个重力值。为了防止列的拉伸,请确保列中的其中一个组件没有定义一个权重值或一个重力值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值