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

最佳答案

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

关于android - MotionLayout:如何为边距设置动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54635533/

10-14 23:46