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.

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

扫描二维码关注公众号,回复: 2451175 查看本文章

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" />

猜你喜欢

转载自blog.csdn.net/agoddog/article/details/80475814