【发布时间】:2021-10-09 13:50:20
【问题描述】:
我想在约束布局 2.1 中实现滑动时的拉伸功能。我有我想在向下滑动视图时扩展的motionlayout。如果我使用新的 Spring 属性,只有当我让转换自动完成时,我才会获得很好的超调效果,但是如果我完全通过滑动完成动画,它会停止而没有任何弹簧效果。我想要有过度拉伸效果,当我释放它时,应该有一些基于弹簧值的弹簧动画。有可能吗?
这是我当前的代码
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
app:layoutDescription="@xml/scene_02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:focusableInTouchMode="false"
android:background="@color/black_semi"
app:layout_constraintStart_toStartOf="parent">
<View
android:id="@+id/area"
android:layout_width="1dp"
android:layout_height="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<View
android:id="@+id/button"
android:background="@color/error_red"
android:layout_width="164dp"
android:layout_height="34dp"
android:layout_marginBottom="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.motion.widget.MotionLayout>
运动文件
<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">
<OnSwipe
motion:springStiffness="80"
motion:springDamping="5"
motion:autoCompleteMode="spring"
motion:dragDirection="dragDown"
motion:touchAnchorId="@id/button"
motion:touchRegionId="@id/button"
motion:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/button">
<Layout
android:layout_width="164dp"
android:layout_height="34dp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="20dp" />
</Constraint>
</ConstraintSet>
<ConstraintSet
android:id="@+id/end"
motion:deriveConstraintsFrom="@id/start">
<Constraint android:id="@id/button"
motion:quantizeMotionInterpolator="overshoot">
<Layout
android:layout_width="164dp"
android:layout_height="34dp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="200dp" />
</Constraint>
</ConstraintSet>
</MotionScene>
【问题讨论】:
标签: android android-constraintlayout android-motionlayout