Loading... 最近Android又新推出了Material Animation,于是再对动画做一些总结。 以前在CSDN上写了一篇[Android动画大合集](https://blog.csdn.net/unicorn97/article/details/80796234),只是简单罗列了一下动画,没有过多的代码,缺少实战指导意义,因此推荐一下最近看到不错的博文 掘金上的作者新小梦写了多篇其他的动画实战文章: * [Android属性动画,看完这篇够用了吧](https://juejin.im/post/6846687601118691341) * [Android矢量图动画:每人送一辆掘金牌小黄车](https://juejin.im/post/6847902224396484621) * [Android过渡动画,发现掘金小秘密](https://juejin.im/post/6850037271714856968) Material Animation属于MDC-Android,下面先介绍MDC-Android: # [material-components-android](https://github.com/material-components/material-components-android) Google的MD团队制定了一些新的MD规范,计划使用MDC来取代Design Support Library,Material Components for Android提供了Material主题,darkmode支持,新的Material组件等。 在[Migrating to Material Components for Android](https://medium.com/androiddevelopers/migrating-to-material-components-for-android-ec6757795351)一文中,介绍了如何从现在的Design Support Library的使用移植到新的MDC上,建议要先使用AndroidX,如果仍然是用的support包的话,那只通过`com.android.support:design:28.0.0`来使用Material组件,但是由于官方已经不再更新support包,所以如果计划使用MDC的,那么还是要先将项目转移到Android Jetpack上,也就是使用AndroidX。 ## 添加依赖 依赖使用: ```gradle allprojects { repositories { google() jcenter() } } ``` ```gradle dependencies { // ... implementation 'com.google.android.material:material:<version>' // ... } ``` 最新版本可以到[Google's Maven Repository](https://maven.google.com/web/index.html#com.google.android.material:material) 或者 [MVN Repository](https://mvnrepository.com/artifact/com.google.android.material/material)查询 要使用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` 比如: ```xml <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight"> <!-- ... --> </style> ``` 关于Theme级别的一些属性设置可以参考[Theming](https://github.com/material-components/material-components-android/blob/master/docs/theming.md),以及推荐使用DayNight主题的介绍[Dark Theme](https://github.com/material-components/material-components-android/blob/master/docs/theming/Dark.md) 然后就可以在布局文件中添加Material组件了,关于全部的Material组件有哪些,可以参考:[[MDC-Android Components Catalog](https://material.io/components/android/catalog/),同时该文档上也有一些使用MDC的教程: * [MDC-101 Android: Material Components (MDC) Basics (Kotlin)](https://codelabs.developers.google.com/codelabs/mdc-101-kotlin/#0) * [MDC 102: Material Design Structure and Layout](https://codelabs.developers.google.com/codelabs/mdc-102-kotlin/) * [MDC-103: Material Design Theming with Color, Shape, Elevation and Type](https://codelabs.developers.google.com/codelabs/mdc-103-kotlin/) * [MDC-104: Material Design Advanced Components](https://codelabs.developers.google.com/codelabs/mdc-104-kotlin/) * [MDC-111 Android: Incorporating Material Components into your codebase (Kotlin)](https://codelabs.developers.google.com/codelabs/mdc-111-kotlin/#5) * [Building Beautiful Transitions with Material Motion for Android](https://codelabs.developers.google.com/codelabs/material-motion-android/#0) 这就是MDC中关于动画的部分 # Material's motion system for Android 在codelab:[Building Beautiful Transitions with Material Motion for Android](https://codelabs.developers.google.com/codelabs/material-motion-android/#0)中,提到了`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 动效系统](http://mp.weixin.qq.com/s?__biz=MzAwODY4OTk2Mg==&mid=2652053241&idx=1&sn=3acbb76b5f9c734cd05c05c70f20e179&chksm=808cbebcb7fb37aa274c47cdef4940b5ed0233ade82d16cdf02c7c08509539f8d4d65b4f0639&scene=21#wechat_redirect)包含一套 (四种) 转场动画模式。它们可以帮助用户理解应用并在其中导航浏览,还能增强组件之间或全屏视图之间的联系。这些转场模式包括: * [容器变换](https://material.io/design/motion/the-motion-system.html#container-transform) * [共享轴](https://material.io/design/motion/the-motion-system.html#shared-axis) * [淡入淡出](https://material.io/design/motion/the-motion-system.html#fade-through) * [弹出](https://material.io/design/motion/the-motion-system.html#fade) MD团队给出了几个完整的应用例子:[material-components-android-examples](https://github.com/material-components/material-components-android-examples) 更多关于Material的Motion和Theme、组件的内容,可以参考: [Android Material 组件 1.2.0 现已发布](https://mp.weixin.qq.com/s/PZD8RxrqP7_RAjXIo345aQ) # 总结: 现状是设计团队在设计新的图稿和交互时,也很少会参考MD的规范,说白了就是设计师设计难,程序员实现难,所以Material风格应用不多,如果是新开发的一个APP,且使用AndroidX(都已经是新开发了,为什么不用呢),可以考虑使用MDC,且学习成本也不是很大,如果是要面向海外的应用,那么Google Play还能加以推荐。 作为开发者个人而言,虽然目前MDC仍处于起步阶段,还有很多组件等会更新,但现在也正是开始学习Material主题的好时候。 Google会继续推广MDC,在Flutter和Android中都已经给出了相应的实现库,且会使得我们开发Material风格的应用越来越容易,IOS和Android都在互相借鉴设计风格,应用都朝着扁平化的方向发展,所以开始你的MDC之旅吧。 # More: 对于一些网络图片的共享元素转场,要等到图片加载完成之后再做处理,可以参考: [Glide实现共享元素无缝转场效果,只需四步!](https://mp.weixin.qq.com/s/7TRd3RP_ge4QCoFz79P6Zw) © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 ×Close 赞赏作者 扫一扫支付 0