Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 约束布局设置运行时约束Start\u toEndOf_Android_Android View_Android Constraintlayout_Android Design Library - Fatal编程技术网

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几乎没有什么不同,您只需添加
    可能在末尾