Android 约束布局设置运行时约束Start\u toEndOf
我有个限制Android 约束布局设置运行时约束Start\u toEndOf,android,android-view,android-constraintlayout,android-design-library,Android,Android View,Android Constraintlayout,Android Design Library,我有个限制 app:layout\u constraintStart\u toStartOf=“parent”。运行时我需要将此约束更改为app:layout\u constraintStart\u toEndOf=“@+id\myid” 从我的研究中,我只发现了constraintSet.connect(viewid,constraintSet.END,constraintSet.PARENT_ID,constraintSet.END,50)。但是如何用这个来达到我的要求。有什么想法吗 这在k
app:layout\u constraintStart\u toStartOf=“parent”
。运行时我需要将此约束更改为app:layout\u constraintStart\u toEndOf=“@+id\myid”
从我的研究中,我只发现了
constraintSet.connect(viewid,constraintSet.END,constraintSet.PARENT_ID,constraintSet.END,50)代码>。但是如何用这个来达到我的要求。有什么想法吗 这在kotlin
中,但它与Java
几乎没有什么不同
为rootLayout
提供一个ID李>
现在,使用以下代码:
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
ProTip:您还可以通过在rootLayout
(XML)中将animateChange
设置为true
来设置更改的动画,或者您可以使用我一直喜欢的转换
动画
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
您可以使用yourView.animate()进一步添加Alpha
动画。Alpha(1f)。duration=700//1f(0到1)是值,700是持续时间
记住,它与Java几乎没有什么不同,您只需添加代码>可能在末尾