zoukankan      html  css  js  c++  java
  • Android动画之硬件加速

    你的动画写出来卡嘛?流畅嘛

    如果你想提升动画的性能,那就是用它-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/

  • 相关阅读:
    windows类型
    网络编程socket、udp
    mem族函数与str族函数(待填)
    位运算符的用处(待填)
    c51较c比较,单片机最小系统
    数据结构之 顺序栈的操作
    [置顶] 数据结构之 顺序栈的操作
    java中常用的帮助类。加快开发速度
    php实现安装程序的 安装
    php压缩文件帮助类
  • 原文地址:https://www.cnblogs.com/spring87/p/5034397.html
Copyright © 2011-2022 走看看