提问者:小点点

如何复制YouTube的“下拉退出全屏”手势?


我正在尝试用exoplayer创建一个应用程序,我想像youtube应用程序那样实现一个“下拉退出全屏”的手势。 手势本身似乎可以使用手势探测器,但我不知道如何创建“下拉和缩小整个视频”的效果。

像这样

我如何实现这一点?


共1个答案

匿名用户

为了实现这一点,我认为您可以使用MotionLayout。 您可以查看以下文档:https://developer.android.com/training/constraint-layout/motionlayout/examples

使用MotionLayout,你可以有一个视图,它可以是你的全屏视频或其他任何东西,你可以根据用户的拖动动作来制作动画。 它在MotionScene中定义动画,如下所示:

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

    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="1000"
        motion:motionInterpolator="linear">
        <OnSwipe
            motion:dragDirection="dragRight"
            motion:touchAnchorId="@id/button"
            motion:touchAnchorSide="right" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint
            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">
            <CustomAttribute
                motion:attributeName="BackgroundColor"
                motion:customColorValue="#D81B60" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            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">
            <CustomAttribute
                motion:attributeName="BackgroundColor"
                motion:customColorValue="#9999FF" />
        </Constraint>
    </ConstraintSet>

</MotionScene>

您可以看到,您可以将动作定义为一个新节点,如onswipe,在那里您可以指定方向和触摸属性。 我认为文档可以帮助扩展所有的可能性,请看一看。