android - 是否可以在没有动画的情况下在 MotionLayout 中设置结束状态?

标签 android android-recyclerview android-animation android-constraintlayout android-motionlayout

我有一些项目被包裹在 motionLayout 和 recyclerView 中,其中需要将一个项目设置为结束状态,并将其余项目保持在开始状态,没有任何动画或闪烁,只是显示。 enter image description here

当我尝试调用

transitionToState(endState)

transitionToEnd()

动画发生了,但我只需要在第一次将元素设置为结束状态。 当用户点击项目时,一切都应该是动画的

最佳答案

通过执行以下操作,您可以在没有动画的情况下过渡到 MotionLayout 的结束状态:

yourMotionLayout.setTransitionDuration(0)
yourMotionLayout.transitionToEnd()

您可以将其包装到扩展函数中以便于重用:

/**
 * Triggers the underlying [MotionLayout] to transition to end state immediately.
 */
fun MotionLayout.jumpToEnd() {
    this.setTransitionDuration(0)
    this.transitionToEnd()
}

关于android - 是否可以在没有动画的情况下在 MotionLayout 中设置结束状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64861925/

相关文章:

Android - 通过 Intent.FLAG_ACTIVITY_CLEAR_TOP 通过保持状态返回到特定 Activity

android - 隐藏在 ActionBar 后面的 Listview

android - 子回收器 View 的预取 View 不起作用

android - fragment OnclickListener RecyclerView

java - 将动画延迟放在属于 1 个动画集的 ImageView 和 TextView 上

java - 在 Android 中获取 ArrayList 项目的旧位置

java - KeyListener 不工作,即使它看起来是正确的

android - 在启动器应用程序上向上和向下滑动手势

android - 禁用 NavigationDrawer 图标的幻灯片动画

android动画将圆形图像向各个方向扩展