最近Android又新推出了Material Animation,于是再对动画做一些总结。
以前在CSDN上写了一篇Android动画大合集,只是简单罗列了一下动画,没有过多的代码,缺少实战指导意义,因此推荐一下最近看到不错的博文
掘金上的作者新小梦写了多篇其他的动画实战文章:
Material Animation属于MDC-Android,下面先介绍MDC-Android:
material-components-android
Google的MD团队制定了一些新的MD规范,计划使用MDC来取代Design Support Library,Material Components for Android提供了Material主题,darkmode支持,新的Material组件等。
在Migrating to Material Components for Android一文中,介绍了如何从现在的Design Support Library的使用移植到新的MDC上,建议要先使用AndroidX,如果仍然是用的support包的话,那只通过com.android.support:design:28.0.0
来使用Material组件,但是由于官方已经不再更新support包,所以如果计划使用MDC的,那么还是要先将项目转移到Android Jetpack上,也就是使用AndroidX。
添加依赖
依赖使用:
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
// ...
implementation 'com.google.android.material:material:<version>'
// ...
}
最新版本可以到Google's Maven Repository 或者 MVN Repository查询
要使用Android 10 编译,compileSdkVersion
设置为 29
,使用AppCompatActivity
,将主题继承自以下的Material主题之一:
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar
比如:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
关于Theme级别的一些属性设置可以参考Theming,以及推荐使用DayNight主题的介绍Dark Theme
然后就可以在布局文件中添加Material组件了,关于全部的Material组件有哪些,可以参考:[MDC-Android Components Catalog,同时该文档上也有一些使用MDC的教程:
- MDC-101 Android: Material Components (MDC) Basics (Kotlin)
- MDC 102: Material Design Structure and Layout
- MDC-103: Material Design Theming with Color, Shape, Elevation and Type
- MDC-104: Material Design Advanced Components
- MDC-111 Android: Incorporating Material Components into your codebase (Kotlin)
- Building Beautiful Transitions with Material Motion for Android 这就是MDC中关于动画的部分
Material's motion system for Android
在codelab:Building Beautiful Transitions with Material Motion for Android中,提到了MDC-Android
库提供的变换类是基于AndroidX Transition library(androidx.transition
,支持API14+) 和 Android Framework Transition library (android.transition
,支持API 21+),因此要使用MDC中的Transition类,最低兼容的只能到API 21 ,也就是Android 5.0,不过目前多数APP应该已经把5.0设为最低兼容版本了。
Material 动效系统包含一套 (四种) 转场动画模式。它们可以帮助用户理解应用并在其中导航浏览,还能增强组件之间或全屏视图之间的联系。这些转场模式包括:
MD团队给出了几个完整的应用例子:material-components-android-examples
更多关于Material的Motion和Theme、组件的内容,可以参考:
Android Material 组件 1.2.0 现已发布
总结:
现状是设计团队在设计新的图稿和交互时,也很少会参考MD的规范,说白了就是设计师设计难,程序员实现难,所以Material风格应用不多,如果是新开发的一个APP,且使用AndroidX(都已经是新开发了,为什么不用呢),可以考虑使用MDC,且学习成本也不是很大,如果是要面向海外的应用,那么Google Play还能加以推荐。
作为开发者个人而言,虽然目前MDC仍处于起步阶段,还有很多组件等会更新,但现在也正是开始学习Material主题的好时候。
Google会继续推广MDC,在Flutter和Android中都已经给出了相应的实现库,且会使得我们开发Material风格的应用越来越容易,IOS和Android都在互相借鉴设计风格,应用都朝着扁平化的方向发展,所以开始你的MDC之旅吧。
More:
对于一些网络图片的共享元素转场,要等到图片加载完成之后再做处理,可以参考: