[]List组件拖动浏览时item会出现重叠的现象
module list.datasource {
import List = laya.ui.List;
export class ListDataSourceMediator {
constructor() {
}
public setUp():void
{
var list: List = new List();
// 渲染的item
list.itemRender = ListDataSourceItem;
// 设置行列显示的item个数
list.repeatX = 1;
list.repeatY = 4;
// list居中显示
list.x = (Laya.stage.width - ListDataSourceItem.WID) / 2;
list.y = (Laya.stage.height - ListDataSourceItem.HEI * list.repeatY) / 2;
// 使用但隐藏滚动条,滚动条水平滚动
list.vScrollBarSkin = ""; // list.vScrollBarSkin 滚动条垂直滚动
//item对象是否可选以及选中后可做的操作
list.selectEnable = true;
list.selectHandler = new Handler(this, this.onSelect);
// 滚动条的橡皮筋操作:回弹时间及弹性距离
list.scrollBar.elasticBackTime = 200;
list.scrollBar.elasticDistance = 5;
Laya.stage.addChild(list);
// 设置数据项为对应图片的路径
var data: Array<string> = [];
for (var i: number = 0; i < 2; ++i) {
data.push("img_common_pinzhi0.png");
data.push("img_common_pinzhi1.png");
data.push("img_common_pinzhi2.png");
data.push("img_common_pinzhi3.png");
data.push("img_common_pinzhi4.png");
data.push("img_common_pinzhi5.png");
}
// item使用的列表数据
list.dataSource = data;
}
private onSelect(index: number): void {
console.log("当前选择的索引:" + index);
}
}
import Box = laya.ui.Box;
import Image = laya.ui.Image;
import Label = Laya.Label;
export class ListDataSourceItem extends Box {
public static WID: number = 200;
public static HEI: number = 20;
// private _img: Image = null;
private _lb:Label = null;
constructor() {
super();
this._lb = new Label();
this._lb.size(ListDataSourceItem.WID, ListDataSourceItem.HEI);
this.addChild(this._lb);
// this._img = new Image();
// this._img.size(ListDataSourceItem.WID, ListDataSourceItem.HEI);
// this.addChild(this._img);
}
public set dataSource(path: string) {
// this._img.skin = path;
this._lb.text = path;
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
lzgyy123
赞同来自:
CGH
赞同来自: