gpt4 book ai didi

java - Android MotionLayout : How to handle both click and swipe events on same view?(包括视频示例)

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

我需要在我的应用程序中实现这一点。
最好看一下视频示例,因为我无法用文字准确地解释它:

拖动 Action :https://streamable.com/i0aen

点击 Action :https://streamable.com/7eahj

我能够相互独立地实现它们。但我不能设法一起做。我使用的是单个运动场景文件。我可以注释掉一个转换,而另一个工作,但如果我让他们两个布局根本不起作用,我猜一个转换捕获另一个转换并停止。有没有办法在同一个 View 上实现这两个事件?这是motion_scene的代码:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<!-- <Transition-->
<!-- android:id="@+id/dragTransition"-->
<!-- motion:constraintSetEnd="@+id/endDrag"-->
<!-- motion:constraintSetStart="@+id/startDrag"-->
<!-- motion:duration="1000">-->
<!-- <OnSwipe-->
<!-- motion:dragDirection="dragDown"-->
<!-- motion:touchAnchorId="@id/menuBtnFrFr"-->
<!-- motion:touchAnchorSide="top" />-->
<!-- </Transition>-->

<Transition
android:id="@+id/clickTransition"
motion:constraintSetEnd="@+id/endClick"
motion:constraintSetStart="@+id/startClick"
motion:duration="300">
<OnClick motion:targetId="@id/menuBtnFrFr" />
</Transition>

<ConstraintSet android:id="@+id/startDrag">
<Constraint
android:id="@+id/menuBtnFrFr"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginLeft="75dp"
android:layout_marginRight="75dp"
android:background="#00000000"
android:src="@drawable/logo"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircleOutside"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_below="@id/top_label"
android:layout_gravity="center"
android:layout_margin="15dp"
android:background="@drawable/circle_dark"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircle"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_margin="45dp"
android:background="@drawable/circle"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/uploadBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:visibility="gone"
android:orientation="vertical"
android:layout_marginTop="440dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/recordBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitXY"
android:gravity="center"
android:visibility="gone"
android:layout_marginTop="400dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.24"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/gifBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitCenter"
android:gravity="center"
android:layout_marginTop="400dp"
android:visibility="gone"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintHorizontal_bias="0.76"
motion:layout_constraintVertical_bias="0.5">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
</ConstraintSet>

<ConstraintSet android:id="@+id/endDrag">
<Constraint
android:id="@+id/menuBtnFrFr"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="75dp"
android:layout_marginRight="75dp"
android:background="#00000000"
android:src="@drawable/logo"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.98">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="0" />
</Constraint>
<Constraint
android:id="@+id/bgCircle"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_margin="45dp"
android:background="@drawable/circle"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircleOutside"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="@id/top_label"
android:layout_gravity="center"
android:layout_margin="15dp"
android:background="@drawable/circle_dark"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/uploadBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:visibility="gone"
android:orientation="vertical"
android:layout_marginTop="440dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/recordBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitXY"
android:gravity="center"
android:visibility="gone"
android:layout_marginTop="400dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.24"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/gifBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitCenter"
android:gravity="center"
android:layout_marginTop="400dp"
android:visibility="gone"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintHorizontal_bias="0.76"
motion:layout_constraintVertical_bias="0.5">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/startClick">
<Constraint
android:id="@+id/menuBtnFrFr"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginLeft="75dp"
android:layout_marginRight="75dp"
android:background="#00000000"
android:src="@drawable/logo"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircleOutside"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_below="@id/top_label"
android:layout_gravity="center"
android:layout_margin="15dp"
android:background="@drawable/circle_dark"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircle"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:layout_margin="45dp"
android:background="@drawable/circle"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/uploadBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/recordBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitXY"
android:gravity="center"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.24"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/gifBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitCenter"
android:gravity="center"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintHorizontal_bias="0.76"
motion:layout_constraintVertical_bias="0.5">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
</ConstraintSet>

<ConstraintSet android:id="@+id/endClick">
<Constraint
android:id="@+id/menuBtnFrFr"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginLeft="75dp"
android:layout_marginRight="75dp"
android:layout_marginBottom="35dp"
android:background="#00000000"
android:src="@drawable/logo"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircle"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_gravity="center"
android:layout_margin="45dp"
android:background="@drawable/circle"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="35dp">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/bgCircleOutside"
android:layout_width="600dp"
android:layout_height="600dp"
android:layout_below="@id/top_label"
android:layout_gravity="center"
android:layout_margin="15dp"
android:background="@drawable/circle_dark"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintDimensionRatio="1:1"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="35dp">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/uploadBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:layout_marginTop="440dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/recordBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitXY"
android:gravity="center"
android:layout_marginTop="400dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.24"
motion:layout_constraintVertical_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
<Constraint
android:id="@+id/gifBtn"
android:layout_width="@dimen/button_size"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical"
android:scaleType="fitCenter"
android:gravity="center"
android:layout_marginTop="400dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintHorizontal_bias="0.76"
motion:layout_constraintVertical_bias="0.5">
<CustomAttribute
motion:attributeName="Saturation"
motion:customFloatValue="1" />
</Constraint>
</ConstraintSet>
</MotionScene>

这是否可以在相同的 View 上实现?如果没有,您将如何创建此布局有一些建议吗?提前致谢。

最佳答案

是的,这很容易。
只需单击用于预览运动布局的指示线。在属性窗口中,您可以同时添加 onclick 和 onswipe 方法。
只需添加目标 ID 和操作。
干得好。
screenshot

关于java - Android MotionLayout : How to handle both click and swipe events on same view?(包括视频示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60040018/

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