好的,經過一番努力就解決了。想我會把它在這裏爲他人:
這可以通過擴展列表元素簡單地加以解決,並檢測ListItemRenderer和修改幾行:
首先登場,擴展列表元素:
package au.com.keeghan.controls {
import mx.controls.List;
import mx.core.ClassFactory;
public class ExtendedList extends List{
public function ExtendedList(){
super();
itemRenderer = new ClassFactory(ExtendedListItemRenderer);
}
}
}
現在我們要擴展新創建的項目渲染器(ExtendedListItemRenderer)。因爲實際上並不需要太多的代碼,所以我們可以把它放在同一個.as文件中。爲此,我們宣佈它作爲一個內部類,並定位其上的包外...只是右括號下面:現在
import mx.controls.listClasses.ListItemRenderer;
internal class AsOneListItemRenderer extends ListItemRenderer{
override protected function measure():void{
super.measure();
var w:Number = 0;
if (icon)
w = icon.measuredWidth;
// Guarantee that label width isn't zero
// because it messes up ability to measure.
if (label.width < 4 || label.height < 4)
{
label.width = 4;
label.height = 16;
}
if (isNaN(explicitWidth))
{
w += label.getExplicitOrMeasuredWidth();
measuredWidth = w;
measuredHeight = label.getExplicitOrMeasuredHeight();
}
else
{
measuredWidth = explicitWidth;
label.setActualSize(Math.max(explicitWidth - w, 4), label.measuredHeight + 3);
label.validateNow();
label.height = label.textHeight + 5;
measuredHeight = label.getExplicitOrMeasuredHeight() + 3;
if (icon && icon.measuredHeight > measuredHeight){
measuredHeight = icon.measuredHeight;
}
}
}
}
,大部分上面的代碼實際上是剛剛從複製的ListItemRenderer ,神奇的出現向下探底......具體地,這些線路:
label.setActualSize(Math.max(explicitWidth - w, 4), label.measuredHeight + 3);
label.validateNow();
label.height = label.textHeight + 5;
measuredHeight = label.getExplicitOrMeasuredHeight() + 3;
所有我在這裏做的是增加一些高度,兩者的標籤,整體是measuredHeight這到底是導致這一問題的事情。
這個解決方案唯一的缺點就是你會在listItem元素下面獲得大量的填充,但是你仍然可以通過玩弄verticalAlign和填充css屬性來使它看起來很好。