android往返运动动画,使用 MotionLayout 管理运动和微件动画

创建 MotionScene:在之前的 MotionLayout 示例中,app:layoutDescription 属性引用一个 MotionScene。MotionScene 是一个 XML 资源文件,其中包含相应布局的所有运动描述。为了将布局信息与运动描述分开,每个 MotionLayout 都引用一个单独的 MotionScene。请注意,MotionScene 中的定义优先于 MotionLayout 中的任何类似定义。

下面的示例 MotionScene 文件描述了图 1 中的基本水平运动:

xmlns:motion="http://schemas.android.com/apk/res-auto">

motion:constraintSetStart="@+id/start"

motion:constraintSetEnd="@+id/end"

motion:duration="1000">

motion:touchAnchorId="@+id/button"

motion:touchAnchorSide="right"

motion:dragDirection="dragRight" />

android:id="@+id/button"

android:layout_width="64dp"

android:layout_height="64dp"

android:layout_marginStart="8dp"

motion:layout_constraintBottom_toBottomOf="parent"

motion:layout_constraintStart_toStartOf="parent"

motion:layout_constraintTop_toTopOf="parent" />

android:id="@+id/button"

android:layout_width="64dp"

android:layout_height="64dp"

android:layout_marginEnd="8dp"

motion:layout_constraintBottom_toBottomOf="parent"

motion:layout_constraintEnd_toEndOf="parent"

motion:layout_constraintTop_toTopOf="parent" />

请注意以下几点:

包含运动的基本定义。

motion:constraintSetStart 和 motion:constraintSetEnd 指的是运动的端点。这些端点在 MotionScene 后面的 元素中定义。

motion:duration 指定完成运动所需的毫秒数。

可让您通过轻触控制运动。

motion:touchAnchorId 指的是您可以滑动并拖动的视图。

motion:touchAnchorSide 表示我们从右侧拖动视图。

motion:dragDirection 表示拖动的进度方向。例如,motion:dragDirection="dragRight" 表示当您向右拖动时,进度会增加。

是定义描述您的运动的各种限制条件的位置。在此示例中,我们为运动的每个端点定义一个 ConstraintSet。这些端点垂直居中(通过 app:layout_constraintTop_toTopOf="parent" 和 app:layout_constraintBottom_toBottomOf="parent")。在水平方向上,端点位于屏幕最左侧和最右侧。

如需详细了解 MotionScene 支持的各种元素,请参阅 MotionLayout 示例。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值