30天学习笔记 -day 26-Motion Editor(上篇)

Motion Editor是自 Android Studio 4.0 版本开始为MotionLayout布局型别所构建的视觉化编辑气,用於建立动画效果。
MotionLayout是ConstraintLayout 的子类别,可以将任何的ConstraintLayout转换成MotionLayout。

将constraintlayout转换於motionLayout

https://ithelp.ithome.com.tw/upload/images/20210909/20138966bblbOjSDos.png

转换结束会发现在res目录之下有xml资料夹
https://ithelp.ithome.com.tw/upload/images/20210909/20138966PfWZm3Wp6K.png

activity_motion_scene.xml

设定使用者与ui互动会显示的动画,
button(id为button)被我滑动的时候,会从开始的ConstraintSet至结束的ConstraintSet所进行的动画。

<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:dragDirection="dragUp"
        motion:touchAnchorId="@id/button"
        motion:touchAnchorSide="top"/>
    </Transition>
    <!-- 动画开始 -->
    <ConstraintSet android:id="@+id/start">
        <Constraint
            motion:layout_constraintVertical_bias="0.877"
            android:layout_height="wrap_content"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_width="wrap_content"
            android:id="@+id/button" />
    </ConstraintSet>
    <!-- 动画结束 -->
    <ConstraintSet android:id="@+id/end">
        <Constraint
            motion:layout_constraintVertical_bias="0.109"
            android:layout_height="wrap_content"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            android:layout_width="wrap_content"
            android:id="@+id/button" />
    </ConstraintSet>
</MotionScene>

Transition里的:
motion:constraintSetEnd="@+id/end" :表示动画结束的布局id
motion:constraintSetStart="@id/start":表示动画开始的布局id
motion:duration="1000" //动画执行的时间
OnSwipe:使用者与ui互动的方法

  • motion:dragDirection="" 控制元件拉的方向(有 dragUp (向上移动)/ dragDown(向下移动) / dragRight(向右移动) / dragLeft(向左移动) )这4种
  • motion:touchAnchorId=""设定可互动的元件
  • motion:touchAnchorSide=""设定滑动区域

成果
这样就可以完成简单的动画了~


<<:  26. 从学生社团到技术社群 x Girls in Tech x 曼陀号计画

>>:  [Day 30]餐後甜点-心得总结及Python小魔术分享

#26 初探 Electron

前两天我们做了一个网页服务器,接下来我们来帮它加上 GUI 吧! Electron Electron...

30天学习笔记 -day 24-Dagger (下篇)

今天会补充dagger的用法。 今天目标:一个 Acomponent 里放着 Fruit.class...

Day16-旧网站重写成Vue_7_点击滚动

今天终於把整个网站改完了 今天主要讲点击按钮滚动至该区块的部分 先把内容补完,因为我的留言版并没有真...

JavaScript学习日记 : Day17 - Async Await

上一篇介绍到Promise可以用来处理非同步行为,但始终在阅读性方面还是不是很优,今天要介绍的是基於...

成为工具人应有的工具包-01 FullEventLogView

Windows Event Log & FullEventLogView LOG 是监识调查...