2012/03/12

android:layerType 的設定

我們可以設定View用哪種方法來Render


其中的none(Don't use a layer, aka disabled),我不太懂它的意義,我猜應該是不分層次的去處理這個View,而software跟hardware就很清楚字意上的意思了。


SOFTWARE裡的定義是,一旦View指定了用這個參數,就算硬體加速有打開(或有支援)還是要求系統用Android的軟體方式來把View繪製出來。


軟體層可以把硬體加速(HA)不支援的物件繪製出來,可以算是互補的把圖像處理掉,並且暫存起來。但也因為它會暫存,表示如果需要不斷更新畫面,連續的存取代表著就是速度會變慢!因此如果在應用程式中,某個View只需要繪製一次,而硬體加速又可能不支援,我們可以把layerType設定成SOFTWARE。


目前常遇到的案例是,Android 4.0有支援硬體加速,但發佈出去的應用程式支援版本括及2.2甚至更低,所以很不好預測某些ROM是不是寫的很完全,一個自製的4.0 ROM就是強制開啟HA,但承載它的硬體可能根本不支援,簡單的客制化就能讓你的應用程式當掉!


所以,讀了那麼多文件跟說明,回到原點!把android:layerType="software" 拿掉...




後記:


在SW跟HW的文件敘述裡面都有一段一樣的敘述:


From LAYER_TYPE_SOFTWARE:

When the application is using hardware acceleration, a software layer is useful to render drawing primitives not supported by the hardware accelerated pipeline. It can also be used to cache a complex view tree into a texture and reduce the complexity of drawing operations. For instance, when animating a complex view tree with a translation, a software layer can be used to render the view tree only once.
FROM LAYER_TYPE_HARDWARE:

A hardware layer can be used to cache a complex view tree into a texture and reduce the complexity of drawing operations. For instance, when animating a complex view tree with a translation, a hardware layer can be used to render the view tree only once.


無論如何,一定有一段是錯的,或是兩段都是對的!反正Android系統一直改,沒人完全搞懂實際的作法!



沒有留言: