gpt4 book ai didi

android - 运动布局 : Click and Touch not working in view with transition in motion scene (Youtube player like UI)

转载 作者:行者123 更新时间:2023-12-03 17:29:17 24 4
gpt4 key购买 nike

我有一个类似 View 的 Youtube 视频播放器,其中有一个列表,点击后会在下一个屏幕上播放视频。

我已将 Motionscene 添加到视频 View 中,因此在向下拖动时,视频 View 会变小。但这样做时,onClick 或 onTouch 事件不适用于播放/暂停控件。

在 youtube 上,我们可以看到两者都运行良好。所以我想知道我哪里出错了。

运动场景:

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

<Transition
motion:constraintSetEnd="@id/collapsed"
motion:constraintSetStart="@id/expanded"
motion:duration="100">

<OnSwipe
motion:dragDirection="dragDown"
motion:maxAcceleration="200"
motion:touchAnchorId="@+id/player"
motion:touchAnchorSide="bottom" />

</Transition>

<ConstraintSet android:id="@+id/expanded">

<Constraint
android:id="@id/player"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />

<Constraint
android:id="@id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="visible"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/player" />

</ConstraintSet>

<ConstraintSet android:id="@+id/collapsed">

<Constraint
android:id="@id/player"
android:layout_height="85dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />

<Constraint
android:id="@id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/player" />

</ConstraintSet>
</MotionScene>

主布局:
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/youtube_scene"
tools:context=".ProfileActivity"
tools:showPaths="true">


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintBottom_toTopOf="@id/scrollView"
app:layout_constraintTop_toTopOf="parent">

<FrameLayout
android:id="@+id/control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/stop"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/pause"
android:visibility="gone" />

<ImageView
android:id="@+id/start"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/play"
android:visibility="gone" />
</FrameLayout>

<ImageView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3000000"
android:contentDescription="@string/app_name" />
</androidx.constraintlayout.widget.ConstraintLayout>

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/player">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="#dff"
android:gravity="center"
android:text="@string/app_name" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.motion.widget.MotionLayout>

java 代码:
            @Override
public void onClick(View v) {
onVideoClick();
}
});

依赖项:
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'

最佳答案

我通过将所需元素包装在 NestedScrollView 中解决了这个问题

app:layoutDescription="@transition/profile_animations_user_other"
app:showPaths="false">

<androidx.core.widget.NestedScrollView
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/divider">


<LinearLayout ..../>

</androidx.core.widget.NestedScrollView>

profile_animations_user_other
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/view_pager"
app:touchAnchorSide="top" />
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/toolbar"
app:touchAnchorSide="top" />
</Transition>

关于android - 运动布局 : Click and Touch not working in view with transition in motion scene (Youtube player like UI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57679282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com