Android动画之硬件加速
2015-12-09 21:56
471 查看
你的动画写出来卡嘛?流畅嘛
如果你想提升动画的性能,那就是用它-hardware layers。
During animations your views may be redrawn each frame. If you use view layers, instead of having to redraw each frame, views render once into an off-screen buffer which can be reused.
In addition, hardware layers are cached on the GPU, which makes certain operations during animation much faster. Simple transformations (translation, rotation, scaling and alpha) can be rendered quickly with layers. Since many animations are just a combination of these transformations, layers can supercharge animation performance.
如何使用:
http://developer.android.com/intl/zh-cn/reference/android/view/View.html#setLayerType(int, android.graphics.Paint)
当你想缓存的时候就调用她:View.setLayerType(View.LAYER_TYPE_HARDWARE, null)
当动画结束,就用它:
示例代码:
这地方是出处以及源码呦,http://blog.danlew.net/2015/10/20/using-hardware-layers-to-improve-animation-performance/
如果你想提升动画的性能,那就是用它-hardware layers。
During animations your views may be redrawn each frame. If you use view layers, instead of having to redraw each frame, views render once into an off-screen buffer which can be reused.
In addition, hardware layers are cached on the GPU, which makes certain operations during animation much faster. Simple transformations (translation, rotation, scaling and alpha) can be rendered quickly with layers. Since many animations are just a combination of these transformations, layers can supercharge animation performance.
如何使用:
http://developer.android.com/intl/zh-cn/reference/android/view/View.html#setLayerType(int, android.graphics.Paint)
View.setLayerType().
当你想缓存的时候就调用她:View.setLayerType(View.LAYER_TYPE_HARDWARE, null)
当动画结束,就用它:
View.setLayerType(View.LAYER_TYPE_NONE, null).
示例代码:
// Set the layer type to hardware myView.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Setup the animation ObjectAnimator animator = ObjectAnimator.ofFloat(myView, View.TRANSLATION_X, 150); // Add a listener that does cleanup animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { myView.setLayerType(View.LAYER_TYPE_NONE, null); } }); // Start the animation animator.start();
这地方是出处以及源码呦,http://blog.danlew.net/2015/10/20/using-hardware-layers-to-improve-animation-performance/
相关文章推荐
- 【Android】Google Plus---Google Service用于Android APP
- 加速Android Studio/Gradle构建
- android,java代码设置背景色
- 手机终于能连接android studio
- Android常见错误
- 在android wear开发中使用蓝牙调试手表实机
- android开发步步为营之86:关于对阿拉伯语页面文字从右往左的支持
- Android Spinner的setSelection()不成功
- Android布局之ListView
- 读书笔记-Android开发艺术探索-第4章-View的工作原理
- android混合开发,webview的java与js互操作
- 关于 Android 中的 getResource()
- android - Dialogs(2)
- Android自定义对话框(Dialog)位置,大小
- android View的getHeight和getMeasuredHeight的区别
- Volley框架之三 疑难实现
- Android测试
- listview优化
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- 【Android】将图片转换为圆角