【问题标题】:Android - Motion Layout overstretch effectAndroid - Motion Layout 过度拉伸效果
【发布时间】: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


    【解决方案1】:

    老兄,把动作布局抛在脑后,你需要动画吗?尝试使用撰写

    【讨论】:

    • 我同意 Compose 有一些很好的动画 API,但对于我的用例来说,实现起来并不容易。我想根据滑动进度为多个视图位置设置动画,这可以在 compose 上实现,但它需要太多样板代码和计算,而使用 motionlayout 可以很容易地完成这种协调动画。 compose 支持运动布局,但仍然不稳定,所以现在不想在 compose 中使用它。
    猜你喜欢
    • 2015-10-28
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    相关资源
    最近更新 更多