【问题标题】:Is it possible set End State in MotionLayout without animation?是否可以在没有动画的情况下在 MotionLayout 中设置结束状态?
【发布时间】:2021-02-27 21:10:25
【问题描述】:

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

当我尝试打电话时

transitionToState(endState)

或

transitionToEnd()

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

【问题讨论】:

  • 你试过setProgress(1.0f)吗?

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


【解决方案1】:

您可以通过以下操作过渡到不带动画的 MotionLayout 的结束状态:

yourMotionLayout.setTransitionDuration(0)
yourMotionLayout.transitionToEnd()

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

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

【讨论】:

    【解决方案2】:

    您可以通过编程方式寻找过渡:setProgress(1f) 将在没有动画的情况下过渡到结束状态。

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多