flex4 DataGrid 设置行颜色如何重写drawRowBackground方法
展开全部
只说一下思路吧:
你必须重写DataGrid的drawRowBackground方法,例如你可以写个AS类文件,继承自DataGrid:
public class MyDataGrid extends DataGrid
{
public function MyDataGrid()
{
super();
}
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);
}
}
2.然后参考一下DataGrid中drawRowBackground()方法是如何实现的(给你列一下源码中的内容):
protected function drawRowBackground(s:Sprite, rowIndex:int,
y:Number, height:Number, color:uint, dataIndex:int):void
{
var contentHolder:ListBaseContentHolder = ListBaseContentHolder(s.parent);
var background:Shape;
if (rowIndex < s.numChildren)
{
background = Shape(s.getChildAt(rowIndex));
}
else
{
background = new FlexShape();
background.name = "background";
s.addChild(background);
}
background.y = y;
// Height is usually as tall is the items in the row, but not if
// it would extend below the bottom of listContent
var height:Number = Math.min(height,
contentHolder.height -
y);
var g:Graphics = background.graphics;
g.clear();
g.beginFill(color, getStyle("backgroundAlpha"));
g.drawRect(0, 0, contentHolder.width, height);
g.endFill();
}
3.然后根据源码中的内容和你想要的业务逻辑,进行修改即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询