这是我的exml文件结构,然后把exml加载进去.
先初始化,给控件list设置属性和数据
this.sourceArr = new Array();
for (var i:number = 0; i < 40; i++){
//给数据中添加一个含有"label"属性的对象
this.sourceArr.push({label:i});
}
this.arrCollection = new eui.ArrayCollection(this.sourceArr);
this.List_users.dataProvider = this.arrCollection;
this.List_users.itemRenderer = LabelRenderer;
export class LabelRenderer extends eui.ItemRenderer {
private Group_otherdi:eui.Group;
private Image_otherdi:eui.Image;
private label_name:eui.Label;
private head_bg:eui.Image;
private user_head:eui.Image;//头像
private user_name:eui.Label;//名字
private user_money:eui.Label;//金钱
private Image_jinbi:eui.Image;//金币
public constructor(){
super();
this.touchChildren = true;
this.Group_otherdi = new eui.Group();
this.Group_otherdi.width = 300;
this.Group_otherdi.height = 90;
this.addChild( this.Group_otherdi );
this.Group_otherdi.touchEnabled = false;
this.label_name = new eui.Label();
this.Group_otherdi.addChild( this.label_name );
this.label_name.top = 10;
this.label_name.left = 10;
//this.label_name.text = "李逵"
this.user_head = new eui.Image();
this.Group_otherdi.addChild( this.user_head );
this.user_head.source = "BJL_head_10_png"
this.user_head.scaleX = 0.5;
this.user_head.scaleY = 0.5;
this.user_head.x = 20
this.user_name = new eui.Label();
this.user_name.text = "科比.布莱恩特";
this.addChild(this.user_name);
this.user_name.x = 120;
this.user_name.y = 15;
this.user_name.size = 20;
this.Image_jinbi = new eui.Image();
this.addChild(this.Image_jinbi);
this.Image_jinbi.source = "BJL_jinbi";
this.Image_jinbi.x = 120;
this.Image_jinbi.y = 40;
this.user_money = new eui.Label();
this.user_money.text = "10000";
this.addChild(this.user_money);
this.user_money.x = 120+35;
this.user_money.y = 50;
this.user_money.textColor = 0xFCE358;
this.user_money.size = 20;
}
protected dataChanged():void{
//显示数据中的 label 值
this.label_name.text = this.data.label;
}
}
}
这样在LabelRenderer类中的dataChanged函数中改变你想要的。
最后运行结果是这样的:
如果要刷新的话怎么办,重新设置数据刷新就可以了:
public updateUserList(){
this.sourceArr = new Array();
for (var i:number = 1; i < 10; i++){
//给数据中添加一个含有"label"属性的对象
this.sourceArr.push({label:i});
}
this.arrCollection.source = this.sourceArr;
this.arrCollection.refresh();
}
其中scroll设置横向纵向属性
list布局我用的是VerticalLayout
如果想把滑动条影藏的话,可以设置scroll的属性:horizontalScrollBar.autoVisibility = false(横向)
verticalScrollBar.autoVisibility = false;(纵向)
例子:
this.scroller_zhulu.horizontalScrollBar.autoVisibility = false;
如果还想去掉scroll的复用性的话。可以设置属性useVirtualLayout = false;
例子:
this.List_zhulu.useVirtualLayout = false;
这样就可以避免复用所引起的bug