如何复制 YouTube 的 "pull down to exit fullscreen" 手势?
How to replicate YouTubes "pull down to exit fullscreen" gesture?
我正在尝试使用 exoplayer 创建一个应用程序,我想像 youtube 应用程序一样实现“下拉以退出全屏”手势。手势本身似乎可以使用手势检测器来实现,但我不知道如何创建“下拉并缩小整个视频”效果。
Like this
我该如何实现?
要实现这一点,我认为您可以使用 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
一样将动作定义为一个新节点,在那里你可以指定方向和触摸属性。我认为文档可以帮助扩展所有可能性,请看一下。
我正在尝试使用 exoplayer 创建一个应用程序,我想像 youtube 应用程序一样实现“下拉以退出全屏”手势。手势本身似乎可以使用手势检测器来实现,但我不知道如何创建“下拉并缩小整个视频”效果。
Like this
我该如何实现?
要实现这一点,我认为您可以使用 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
一样将动作定义为一个新节点,在那里你可以指定方向和触摸属性。我认为文档可以帮助扩展所有可能性,请看一下。