我目前正在研究將iPad2作爲硬件平臺的Adobe AIR應用程序,並且無法在其中一個屏幕上獲得像樣的滾動性能。我使用的火花列表,自定義項目渲染就像這樣:iPad上的Adobe AIR滾動性能(2) - 我可以期待什麼?
<s:List id="productList" top="116" bottom="0" left="10" right="10"
width="100%"
visible="true" includeInLayout="true"
height="0"
maxHeight="500"
opaqueBackground="#ffffff"
itemRenderer="myRenderer">
</s:List>
本來,我是用的.mxml渲染,但看到討厭的表演後,我決定推出自己的,擴展UIComponent(我「已經離開了包和拉桿,以節省水平空間):
import mx.controls.listClasses.IListItemRenderer;
import mx.core.UIComponent;
import mx.events.FlexEvent;
import mx.utils.ColorUtil;
import spark.components.Label;
import spark.components.TextInput;
public final class OrderViewProductLineTestIR extends UIComponent implements IListItemRenderer
{
public function OrderViewProductLineTestIR()
{
super();
}
// Internal variable for the property value.
private var _data:Object;
private var productName:Label;
private var orderQty:TextInput;
private var stockQty:TextInput;
// Make the data property bindable.
[Bindable("dataChange")]
// Define the getter method.
public function get data():Object
{
return _data;
}
// Define the setter method, and dispatch an event when the property
// changes to support data binding.
public function set data(value:Object):void
{
_data = value;
invalidateProperties();
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
override protected function createChildren():void
{
super.createChildren();
productName = new Label();
// productName.visible = true;
addChild(productName);
orderQty = new TextInput();
addChild(orderQty);
stockQty = new TextInput();
addChild(stockQty);
}
override protected function commitProperties():void
{
super.commitProperties();
productName.text = _data.Name;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
productName.move(0, 0);
productName.setActualSize(250, 48);
orderQty.move(270, 0);
orderQty.setActualSize(100, 48);
stockQty.move(390, 0);
stockQty.setActualSize(100, 48);
}
override protected function measure():void
{
super.measure();
measuredWidth = 490;
measuredHeight = 48;
}
}
正如你可以看到這是非常輕的重量,但我的DataProvider包含的向上的100個項目,其中有11可以在屏幕上在任何時候。我所讀到的關於提高滾動性能的所有內容都圍繞着使用opaqueBackground
和cacheAsBitmap
,但是不管我在這裏嘗試的都不是什麼。在列表級別使用cacheAsBitmap
不會有所幫助,因爲只要滾動了多行代碼就需要重新渲染整個內容,並且在項目渲染器級別使用它仍然非常慢當滾動速度很快時 - 大概是因爲很多文件在非常快的滾動中被一次性回收。
我知道iPad應該沒有問題在60幀/秒的幀中刷新一幀信息,但當我快速滾動時,我看到它奮鬥到10 fps(從視線)。所以問題:我錯過了一些顯而易見的事情,或者這是由於使用AIR時涉及的層數(和向量渲染)而導致的。爲了記錄,我試圖改變應用程序的渲染模式,並嘗試改變幀速率以消除明顯的。
你可能想嘗試一件快捷的事情。在你的情況下,它看起來並不像你需要從覆蓋中調用超級。老實說,雖然你不會從Spark列表中獲得本機性能。如果您有靈活性,您可能需要檢查foxhole GPU組件:https://github.com/joshtynjala/foxhole-starling。 – francis 2012-04-17 00:21:25
不是cacheAsBitmap,對於想要cacheAsBitmapMatrix的手機。請參閱http://www.riagora.com/2010/09/bitmap-caching-for-android/。但即使如此......我經常提醒人們,閃存虛擬機非常糟糕。史蒂夫喬布斯不希望他的設備上有一個原因。我不想在這裏開一場瘋狂的戰鬥,我不是一個蘋果或閃光的變態男人,我只是說實話。 Adobe在LLVM.org上發佈了一個基準測試,顯示AS3的性能約爲本機C的效率的1%,並且在LLVM優化(偶爾)達到30%時達到峯值。 – 2012-04-17 00:44:38
另外我很好奇你正在構建什麼版本的AIR。看到下面的帖子,它可能對您有所幫助http://www.leebrimelow.com/?p=2754。 – 2012-04-17 00:45:39