ConstraintLayout学习

继承关系:


ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way.

ConstraintLayout是一个ViewGroup,它允许你以灵活的方式去定位和调整控件(的大小)。

Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time. This documentation will reflect those changes.

注意:你可以在API等级9的Android系统及以上将ConstraintLayout作为一个支持类库使用。像这样的,我们计划随着时间的推移去丰富它的API和能力。该文档将会反映这些变化。

There are currently various types of constraints that you can use:

如下是当前你可以使用的各种类型的约束:

Note that you cannot have a circular dependency in constraints.

注意,约束中不能具有循环依赖关系。

Also see ConstraintLayout.LayoutParams for layout attributes.

你也可以通过阅读ConstraintLayout.LayoutParams去了解(其)布局属性。

Developer Guide

开发者指南

Relative positioning

相对定位

Relative positioning is one of the basic building block of creating layouts in ConstraintLayout. Those constraints allow you to position a given widget relative to another one. You can constrain a widget on the horizontal and vertical axis:

相对定位是在约束布局中创建布局的基本构建块之一。这些约束允许您将给定的小部件相对于另一个小部件定位。可以在水平和垂直轴上约束小部件:

  • Horizontal Axis: left, right, start and end sides
  • 水平轴:左、右、起点和终点
  • Vertical Axis: top, bottom sides and text baseline
  • 垂直轴:顶部、底部和文本基线

The general concept is to constrain a given side of a widget to another side of any other widget.

一般的概念是将控件的给定边约束到任何其他窗口小部件的另一边。

For example, in order to position button B to the right of button A (Fig. 1): 

例如,为了将按钮B定位到按钮A的右边(如图):


you would need to do:

你需要这样做:

 
<Button android:id="@+id/buttonA" ... /> <Button android:id="@+id/buttonB" ... app:layout_constraintLeft_toRightOf="@+id/buttonA" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值