【问题标题】:MotionLayout: how to animate marginMotionLayout:如何为边距设置动画
【发布时间】:2019-05-25 19:18:28
【问题描述】:

我正在使用MotionLayout 将视图的大小从全屏调整为具有特定边距的较小尺寸(如下所示)。它大部分工作正常,但显示的边距为 0,直到动画结束,然后立即应用它们。有什么方法也可以为这些设置动画吗?

<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@+id/localVideoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@+id/localVideoView"
        android:layout_width="68dp"
        android:layout_height="120dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="92dp"/>
</ConstraintSet>

我尝试使用KeyFrameSet 创建具有不同边距值的中间点,但没有效果。

例如

    <KeyFrameSet>
        <KeyAttribute
            app:framePosition="50"
            app:target="@id/localVideoView">
            <CustomAttribute
                motion:attributeName="layoutMarginBottom"
                motion:customDimension="92dp" />
        </KeyAttribute>
    </KeyFrameSet>

更新

因此,看起来问题与我正在使用 SurfaceView 的事实有关...如果我尝试使用 ImageView,例如边距确实会逐渐变化。

【问题讨论】:

  • 我不知道究竟为什么,但它适用于我使用 MotionLayout 2.0.0 Alpha 3。尝试通过 motion:layout_margin... 在布局标签(约束集 > 约束 > 布局)中定义边距。
  • @jossiwolf 您看到边距逐渐变化了吗?顺便说一句,我在这里也使用 Alpha 3。我尝试对这些属性使用motion:,但在这种情况下边距根本没有改变(即使在动画结束时)
  • @jossiwolf 我可能误解了你的建议......你能在答案中包含你的答案吗?我会试试看?
  • 添加了更新...看起来问题与我使用SurfaceView的事实有关
  • 嗯,这可能是原因 - 虽然我不完全确定为什么:(

标签: android android-motionlayout


【解决方案1】:

SurfaceView 不允许适当的转换,如果您需要转换,您应该使用 TextureView。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-19
    • 2016-11-22
    • 1970-01-01
    • 2020-04-07
    • 2020-01-07
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多