View切换的过渡动画库:TransformationLayout
这是一个用于Activity或者Fragment 以及View切换的过渡动画库,效果非常炫,它使用Material Design的运动系统过渡模式来创建变形动画。该库提供了用于绑定目标视图,设置淡入淡出和路径运动方向以及许多其他自定义选项的属性。
8.1 如何使用?
在build.gradle
中添加如下依赖:
dependencies {
implementation "com.github.skydoves:transformationlayout:1.0.4"
}
然后,需要将我们需要添加过渡动画的View包裹到 TransformationLayout
:
比如我们要将一个fab 过渡到一个card卡片,布局如下:
重点来了,绑定视图,将一个targetView
绑定到TransformationLayout
有2种方式:
- 通过在xml中指定属性:
app:transformation_targetView="@+id/myCardView"
- 在代码中绑定
transformationLayout.bindTargetView(myCardView)
当我们点击fab时,在监听器中调用startTransform()
开始过渡动画,finishTransform()
开始结束动画。
// start transformation when touching the fab.
fab.setOnClickListener {
transformationLayout.startTransform()
}
// finish transformation when touching the myCardView.
myCardView.setOnClickListener {
transformationLayout.finishTransform()
}
更多使用方式请看Github: https://github.com/skydoves/TransformationLayout