Android動畫之硬體加速

來源:互聯網
上載者:User

標籤:

你的動畫寫出來卡嘛?流暢嘛

如果你想提升動畫的效能,那就是用它-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 animationObjectAnimator 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 animationanimator.start();  

  

 

這地方是出處以及源碼呦,http://blog.danlew.net/2015/10/20/using-hardware-layers-to-improve-animation-performance/

Android動畫之硬體加速

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.