gpt4 book ai didi

android - MotionLayout OnSwipe 转换被错误的 anchor 触发

转载 作者:行者123 更新时间:2023-12-05 00:20:57 25 4
gpt4 key购买 nike

所以我们试图模仿可窥视的 BottomSheetLayout 的行为(从屏幕底部向外窥视的底部 View ,向上滚动时进入全屏 View ,有点像这样:https://www.youtube.com/watch?v=yrZVLL-z6P4 ) 使用 MotionLayout,版本 2.0.0-alpha4

问题是可窥视 View 上的 OnSwipe 转换不适用于 View 本身,它显然适用于下方的整个 View ,在本例中为 RecyclerView。所以当我们滚动 RecyclerView 时,转换正在运行。

root_view.xml

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="@dimen/margin_48"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
android:elevation="@dimen/elevation_12"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_12"
android:rotation="90"
app:layout_constraintBottom_toBottomOf="@id/btn"
app:layout_constraintEnd_toEndOf="@id/btn"
app:layout_constraintTop_toTopOf="@id/btn" />

<FrameLayout
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/elevation_8"
app:layout_constraintTop_toBottomOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</FrameLayout>

motion_scene.xml

<Transition
android:id="@+id/swipe"
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:duration="250">

<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn" />
</Transition>

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

<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="parent" />

<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>

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

<Constraint
android:id="@id/fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn" />

<Constraint
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

最佳答案

同时使用 app:tou​​chAnchorIdapp:tou​​chRegionId 帮助了我。

<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/btn"
app:touchRegionId="@id/btn"/>

关于android - MotionLayout OnSwipe 转换被错误的 anchor 触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55724574/

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