【问题标题】:How to set transition duration programmatically in MotionLayout?如何在 MotionLayout 中以编程方式设置过渡持续时间?
【发布时间】:2019-04-30 17:28:50
【问题描述】:

我在这样的代码中手动设置了一个新的过渡:

intro_motion_layout.setTransition(R.id.middle, R.id.end)

有没有办法我也可以这样设置持续时间?

我在 XML 中定义了多个 ConstraintSets,当第一次转换完成时,我使用 onTransitionCompleted 在它们之间切换。我的 XML 中有一个 Transition,它在那里正确使用了持续时间,但我在代码中设置的以下 Transitions 发生得非常快,我找不到改变其持续时间的方法。

【问题讨论】:

    标签: android android-motionlayout


    【解决方案1】:
    intro_motion_layout.setTransition(R.id.middle, R.id.end)
    intro_motion_layout.setTransitionDuration(1000)
    intro_motion_layout.transitionToEnd()
    

    为我工作

    【讨论】:

      【解决方案2】:

      如果你在你的 xml 上定义你的转换,然后你设置你的开始/结束 id,它将从 xml 中获取信息

      <Transition
          app:constraintSetStart="@id/bottom_sheet_closed"
          app:constraintSetEnd="@id/bottom_sheet_open"
          app:duration="1550"
          app:interpolator="easeIn">
      
          <OnSwipe
              app:dragDirection="dragUp"
              app:moveWhenScrollAtTop="true"
              app:touchAnchorId="@id/divider"
              app:touchAnchorSide="top" />
      
      </Transition>
      

      然后您可以通过编程方式执行以下操作:

      root.motion_layout.setTransition(R.id.bottom_sheet_closed, R.id.bottom_sheet_open)
      root.motion_layout.transitionToEnd()
      

      每个想法都会起作用

      【讨论】:

        猜你喜欢
        • 2020-09-08
        • 2014-09-30
        • 2019-10-19
        • 2019-08-26
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        • 2021-12-22
        • 2018-09-20
        相关资源
        最近更新 更多