今天我们将通过继承List组件并重写drawRowBackground函数的方式自定义List的样式..
让List的每个项目以虚线隔开~~
override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number,height:Number,color:uint,dataIndex:int):void
{
super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
var bg:Shape = Shape(s.getChildAt(rowIndex));
//此外为了显示虚线~使用一个while来循环来模拟虚线效果~
var p:Number = 0;
bg.graphics.lineStyle(1,0xCCCCCC);
while(p < listContent.width)
{
bg.graphics.moveTo(p,height-1);
bg.graphics.lineTo(p+4,height-1);
p += 6;
}
}
需要注意的一点~
<L4cd:iList alternatingItemColors="0xFFFFFF" rowHeight="25" dataProvider="{list}"
labelField="label" left="10"
top="10" right="10" bottom="10"/>
要触发drawRowBackground函数~必须先设置alternatingItemColors这个style~因为drawRowBackground的作用是用来画item的背景的,没有设置背景将不会触发drawRowBackground~ 源码下载http://l4cd.net/Blog/article.asp?id=85