我有一个限制条件 app:layout_constraintStart_toStartOf="parent"
. 运行时我需要把这个约束条件改为 app:layout_constraintStart_toEndOf="@+id\myid"
.
从我的研究中,我发现只有 constraintSet.connect(viewid, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 50);
. 但如何实现我的要求与此。有什么想法吗?
这是在 kotlin
但这和 Java
.
rootLayout
. 现在,使用这段代码。
val constraintSet = ConstraintSet()
constraintSet.clone(rootLayout) //Your rootLayout
constraintSet.connect(
yourView.id, //ID of the view whose position you want to change
ConstraintSet.START,
yourMyIdView.id, //ID of the correspondent view
ConstraintSet.END
)
constraintSet.applyTo(rootLayout) //Your rootLayout
小贴士:你也可以通过设置动态变化 animateChange
到 true
在 rootLayout
(XML),或者您可以使用 Transition
我一直比较喜欢的动画。
val transition: Transition = ChangeBounds()
transition.interpolator = AccelerateInterpolator() //Or Any other Interpolator
transition.duration = 700 //Duration
TransitionManager.beginDelayedTransition(rootLayout, transition) //Your rootLayout
constraintSet.applyTo(rootLayout) //Remember to put above 4 lines before this
你可以进一步添加 Alpha
的动画,使用 yourView.animate().alpha(1f).duration = 700 //1f (0 to 1) is the value and 700 is the duration
.
记住,它和Java几乎没有什么不同,你只需要在其中添加上 ;
在最后可能。