springaop引入约束
Constraint Layout is one of the most popular jetpack libraries and we’re happy to share that Constraint Layout 2.0 is out! It has all of the features of Constraint Layout 1.1 that you’re familiar with to build complex layouts quickly, with tooling integrated with Android Studio to preview your XML or even edit your layout.
Constraint Layout是最受欢迎的jetpack库之一,我们很高兴地分享Constraint Layout 2.0的发布! 它具有您熟悉的Constraint Layout 1.1的所有功能,可快速构建复杂的布局,并具有与Android Studio集成的工具来预览XML甚至编辑布局。
Constraint Layout 2.0 brings several new features to Constraint Layout. To use it, bump the version in build.gradle
.
Constraint Layout 2.0为Constraint Layout带来了几个新功能。 要使用它,请在build.gradle
中build.gradle
版本。
implementation “androidx.constraintlayout:constraintlayout:2.0.1”
With the release of 2.0 we’ve also created a github repository for Constraint Layout. It’s currently a read-only repository and we are working to enable pull requests.
在2.0版本中,我们还为Constraint Layout创建了一个github 存储库 。 当前是只读存储库,我们正在努力启用请求请求。
流 (Flow)
Flow is a new virtual layout for building chains that can wrap to the next line, or even another section of the screen, when they run out of room. This is useful when you’re laying out multiple items in a chain but you’re not quite sure how big the container will be at runtime. You can use this to build your layout based on a dynamic size in your application, like screen width on rotation.
Flow是用于构建链的新虚拟布局,当链用完时可以缠绕到下一行甚至屏幕的另一部分。 当您在链中布置多个项目时,这很有用,但是您不确定容器在运行时的大小。 您可以使用它来根据应用程序中的动态尺寸(例如旋转时的屏幕宽度)构建布局。
FlowFlow
Flow
is a virtual layout. Virtual layouts in constraint layout are virtual view groups that participate in constraint and layout, but don’t add levels to your hierarchy. Instead, they reference other views in the Constraint Layout to complete the layout.
Flow
是虚拟布局。 在约束布局虚拟布局是参与约束和布局,但不层级的层次结构添加虚拟视图组。 而是,他们在“约束布局”中引用其他视图以完成布局。
"none""none"
"chain""chain"
"align""align"
You add a Flow
in Constraint Layout 2.0 using the Flow
tag. Flow
creates a virtual view group around the views you pass in constraint_referenced_ids
, laying out the referenced views in a chain.
您添加一个Flow
在约束布局2.0使用Flow
标签。 Flow
将围绕您在constraint_referenced_ids
传递的视图创建一个虚拟视图组,并将参考视图按链排列。
One of the most important options to Flow
is wrapMode
, which allows you to configure what to do when the content overflows (or wraps).
Flow
最重要的选项之一是wrapMode
,它允许您配置内容溢出(或换行)时的处理方式。
You can specify three options for wrapMode
:
您可以为wrapMode
指定三个选项:
none
– create a single chain, overflowing if the content doesn’t fitnone
–创建单个链,如果内容不合适,则溢出chain
– on overflow, create add another chain for the overflow elementschain
–溢出时,创建为溢出元素添加另一个链align
— similar to chain, but align rows into columnsalign
—类似于chain,但将行对齐为列
To learn more about Flow, read the official docs.
要了解有关Flow的更多信息,请阅读官方文档 。
层 (Layer)
A new helper, Layer
, lets you create a virtual layer from several views. Unlike Flow
, it doesn’t lay the views out. Instead, Layer
lets you apply transformations on several views at once.
新的助手Layer
允许您从多个视图创建虚拟层。 与Flow
不同,它不会布局视图。 取而代之的是, Layer
使您可以一次将变换应用于多个视图。
This is useful if you want to build animations to rotate
, translate
, or scale
several views together.
如果要构建动画以一起rotate
, translate
或scale
多个视图,这将很有用。
![Image for post](https://miro.medium.com/freeze/max/9999/1*Tcq1VyL4vhCXCseNBqN6iw.gif)
LayerLayer
A layer is sized during layout, and will be sized based on all of the views it references.
图层在布局期间会调整大小,并将根据其引用的所有视图进行调整。
To add a layer in Constraint Layout 2.0, use the Layer
tag:
要在Constraint Layout 2.0中添加图层,请使用Layer
标记:
动作布局 (Motion Layout)
Motion Layout is one of the most anticipated features in Constraint Layout 2.0. It provides a rich animation system for coordinating animations of multiple views. MotionLayout
is based on ConstraintLayout
and extends it to allow you to animate between multiple sets of constraints (or ConstraintSet
s). You can customize how the views move, scroll, scale, rotate, fade, or even animate custom attributes. It can also handle physics based gestures and control velocity of animations. Animations built with MotionLayout
are seekable and reversible. That means you can jump to any point in the animation, or even play it backwards.
运动布局是约束布局2.0中最令人期待的功能之一。 它提供了一个丰富的动画系统来协调多个视图的动画。 MotionLayout
基于ConstraintLayout
并将其扩展为允许您在多组约束(或ConstraintSet
)之间进行动画处理。 您可以自定义视图如何移动,滚动,缩放,旋转,淡入淡出甚至动画自定义属性。 它还可以处理基于物理的手势并控制动画的速度。 使用MotionLayout
构建的动画是可搜索且可逆的。 这意味着您可以跳到动画中的任何点,甚至可以向后播放。
Integrated in Android Studio, the Motion Editor lets you build, preview, and edit animations using MotionLayout
. This makes it easy to tweak the fine details of an animation when coordinating multiple views.
动作编辑器集成在Android Studio中,可让您使用MotionLayout
,预览和编辑动画。 在协调多个视图时,可以轻松调整动画的精细细节。
Learn more about the Motion Editor read this blog post by Scott Swarthout
了解有关运动编辑器的更多信息,请阅读Scott Swarthout的博客文章。
Learn Motion Layout with a hands-on guide, check out the Motion Layout codelab:
通过动手指南学习运动布局,请查看运动布局代码实验室:
Motion Layout is a general purpose animation tool — you can use it to build pretty much any animation on Android. However, there are two situations where Motion Layout excels at building animations compared to other options.
Motion Layout是一种通用的动画工具-您可以使用它在Android上构建几乎所有动画。 但是,在两种情况下,与其他选项相比,“运动版式”在构建动画方面表现出色。
Seekable animations — animations that are driven by other inputs, such as a collapsing toolbar which responds to scrolling
可搜索的动画 -由其他输入驱动的动画,例如响应滚动的折叠工具栏
State transitions — animations that are driven by a state changing, such as the user entering a screen
状态转换 -由状态更改驱动的动画,例如用户进入屏幕
The new Motion Layout Integrations sample shows how to use Motion Layout to build rich animations for these use cases. Each screen is intended to showcase practical animation effects you can build using Motion Layout as well as how to build integrations with other views.
新的Motion Layout Integrations示例展示了如何使用Motion Layout为这些用例构建丰富的动画。 每个屏幕都旨在展示您可以使用Motion Layout构建的实用动画效果,以及如何与其他视图建立集成。
There’s a lot of new features in Constraint Layout 2.0. Check out the docs, codelab and sample to get started using it in your app.
Constraint Layout 2.0中有很多新功能。 查看文档,代码实验室和示例,以开始在您的应用中使用它。
We can’t wait to see what you build!
我们等不及要看您的建造!
翻译自: https://medium.com/androiddevelopers/introducing-constraint-layout-2-0-9daa3e99995b
springaop引入约束