android 约束 布局
In this tutorial, we’ll be implementing Constraint Layout Animations in our Android Application.
在本教程中,我们将在Android应用程序中实现约束布局动画。
约束布局动画 (Constraint Layout Animation)
We can create beautiful animations using ConstraintLayout quickly. To do so, we need to just change constraints!
我们可以使用ConstraintLayout快速创建精美的动画。 为此,我们只需要更改约束即可!
The most common and easy way to create Constraint Layout animations in by creating two different layouts.
One is the start stage of the animation and the second is the end stage of the animation.
通过创建两个不同的布局来创建约束布局动画的最常见,最简单的方法。
第一个是动画的开始阶段,第二个是动画的结束阶段。
Constraint Set is the class used to set constraints on the views of the Constraint Layout.
约束集是用于在约束布局的视图上设置约束的类。
约束集 (ConstraintSet)
ConstraintSet is the class that is used to define constraints programmatically on the Constraint Layout.
It can also retrieve the constraints present in the Constraint Layout by using clone()
method.
ConstraintSet是用于在Constraint Layout上以编程方式定义约束的类。
它还可以使用clone()
方法检索约束布局中存在的约束。
clone()
method is used to copy the constraints from the layout.
clone()
方法用于从布局复制约束。
applyTo()
is used to apply a constraint set onto the Constraint Layout.
applyTo()
用于将约束集应用于“约束布局”。
A ConstraintSet is created just like any other Java object:
与其他任何Java对象一样,创建ConstraintSet:
ConstraintSet constraintSet = new ConstraintSet();
To set constraints on the views programmatically, we need to use connect()
.
要以编程方式在视图上设置约束,我们需要使用connect()
。
connect()
establishes connections between sibling views or a view and the parent view.
connect()
在兄弟视图或视图与父视图之间建立连接。
To create a ConstraintLayout animation we need:
要创建ConstraintLayout动画,我们需要:
TransitionManager
– To manage the transitions.
beginDelayedTransition()
– To start the transition from the first scene to second scene(first layout to the second layout).
TransitionManager
–管理过渡。
beginDelayedTransition()
–开始从第一个场景到第二个场景(从第一个布局到第二个布局)的过渡。
applyTo()
– To apply the final constraints on the second layout.