Я пытаюсь реализовать анимацию наподобие youtube-video
, представление которой будет свернуто при включении видеоплеера.
Я использую MotionLayout
и создаю MotionScene
с OnSwip
для управления переходом, но сенсорные действия при просмотре, которые удерживают YoutubePlayer, потребляют прикосновение, поэтому MotionLayout
не может контролировать переход
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/videoContainer"
android:layout_width="0dp"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/youtubesupportfragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/cardview_dark_background"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="@id/videoContainer"
app:layout_constraintDimensionRatio="2:1"
app:layout_constraintEnd_toEndOf="@id/videoContainer"
app:layout_constraintStart_toStartOf="@id/videoContainer"
app:layout_constraintTop_toTopOf="@id/videoContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tvVideoTitle"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/videoContainer" />
так как мне нужно играть на YouTube в моем приложении без расширения YoutubeActivity, так что это необходимо для создания фрагментов в пользовательском интерфейсе, поэтому я использую это
val youtube = YouTubePlayerSupportFragment.newInstance()
youtube.initialize(
"KEY",
object : YouTubePlayer.OnInitializedListener {
override fun onInitializationSuccess(
p0: YouTubePlayer.Provider?,
p1: YouTubePlayer?,
p2: Boolean
) {
if (!p2) {
p1?.setFullscreen(false)
// p1?.cueVideo(id)
p1?.loadVideo(id)
}
}
override fun onInitializationFailure(
p0: YouTubePlayer.Provider?,
p1: YouTubeInitializationResult?
) {
"error $p1".log()
}
})
activity?.supportFragmentManager?.beginTransaction()
?.add(R.id.youtubesupportfragment, youtube as Fragment)?.commit()
, это часть Motionscene
<OnSwipe
motion:touchAnchorId="@id/videoContainer"
motion:dragDirection="dragDown"
motion:touchAnchorSide="top" />
Если я не заменяю frameLayout фрагментом, анимация работает нормально, но при переходе фрагмент YouTube использует сенсорный ввод, а движение не воспроизводится.