MotionLayout:如何为边距设置动画

时间:2019-02-11 17:00:34

标签: android android-motionlayout

我正在使用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,则边距确实会逐渐变化。

1 个答案:

答案 0 :(得分:0)

SurfaceView不允许正确的转换。如果需要转换,则应使用TextureView。

相关问题