Motion Editor是自 Android Studio 4.0 版本开始为MotionLayout布局型别所构建的视觉化编辑气,用於建立动画效果。
MotionLayout是ConstraintLayout 的子类别,可以将任何的ConstraintLayout转换成MotionLayout。
转换结束会发现在res目录之下有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互动的方法
成果
这样就可以完成简单的动画了~
<<: 26. 从学生社团到技术社群 x Girls in Tech x 曼陀号计画
>>: [Day 30]餐後甜点-心得总结及Python小魔术分享
前两天我们做了一个网页服务器,接下来我们来帮它加上 GUI 吧! Electron Electron...
今天会补充dagger的用法。 今天目标:一个 Acomponent 里放着 Fruit.class...
今天终於把整个网站改完了 今天主要讲点击按钮滚动至该区块的部分 先把内容补完,因为我的留言版并没有真...
上一篇介绍到Promise可以用来处理非同步行为,但始终在阅读性方面还是不是很优,今天要介绍的是基於...
Windows Event Log & FullEventLogView LOG 是监识调查...