目录


- private barBtnList: Laya.List;
-
- private btnbarListArray = ["按钮1", "按钮2", "按钮3", "按钮4", "按钮5", "按钮6"]
-
- onAwake() {
- this.barBtnList = this.owner.getChildByName("barBtnList") as Laya.List;
- this.barBtnList.repeatX = this.btnbarListArray.length;
- this.barBtnList.repeatY = 1;
- this.barBtnList.spaceX = 30;
- //设置滑动相应
- this.barBtnList.renderHandler = Laya.Handler.create(this, this.onListRender, null, false);
- this.barBtnList.array = this.btnbarListArray;
- this.barBtnList.hScrollBarSkin = "";
- }
-
-
- onListRender(cell: Laya.Button, index: number) {
- let btnName = this.btnbarListArray[index];
- (cell.getChildByName("cx_all") as Laya.Button).label = btnName;
- cell.offAll(Laya.Event.CLICK);
- cell.on(Laya.Event.CLICK, this, () => {
- this.onItemClick(btnName);
- });
- }
-
- onItemClick(name: string) {
- console.log(name);
- }