Egret List

一、EXML设置

二、子项设置

module game {
	export class petListItem extends eui.Component implements eui.IItemRenderer {
		private _data: GameCellData;
		private _itemType: number;
		private headIcon: eui.Image;

		public constructor() {
			super();
		}

		protected partAdded(partName: string, instance: any): void {
			super.partAdded(partName, instance);
		}

		protected childrenCreated(): void {
			super.childrenCreated();
		}
		
		public set data(data: GameCellData) {
			this._data = data;
		}
		public get data(): GameCellData {
			return this._data;
		}
		public selected: boolean;
		public itemIndex: number;
	}
	class GameCellData {
		name: string;
		type: number;
	}
}

三、创建list

module game {
	export class mainGame extends eui.Component implements eui.UIComponent {
		private petList: eui.List;
		private magic: eui.Image;
		private bg: eui.Image;
		private gray: eui.Image;
		private tempImg: eui.Image;
		private game_list_scroller: eui.Scroller;
		private horizontalScrollBar: eui.HScrollBar;
		private dataArray: eui.ArrayCollection;
		private listGroup: eui.Group;

		private listArr: Array<any>;//列表数据
 
		public constructor() {
			super();
		}

		protected partAdded(partName: string, instance: any): void {
			super.partAdded(partName, instance);
		}

		protected childrenCreated(): void {
			super.childrenCreated();

			this.listArr = [
				{ name: "monkeyHead_png", type: 0 },
				{ name: "monkeyHead_png", type: 0 },
				{ name: "sheep_png", type: 1 },
				{ name: "tortoise_png", type: 2 },
				{ name: "sheep_png", type: 1 }
			];

			this.dataArray = new eui.ArrayCollection();
			this.dataArray.replaceAll(this.listArr);

			this.game_list_scroller.horizontalScrollBar = this.horizontalScrollBar;
			this.game_list_scroller.scrollPolicyV = eui.ScrollPolicy.OFF;
			this.game_list_scroller.addEventListener(egret.Event.CHANGE, this.onScrollerChange, this);

			this.petList.itemRenderer = game.petListItem;
			this.petList.dataProvider = this.dataArray;

			this.game_list_scroller.viewport = this.petList;
			this.petList.addEventListener(eui.ItemTapEvent.ITEM_TAP, this.onChange, this);

			this.createMovieClip();

			this.petList.addEventListener(eui.ItemTapEvent.ITEM_TAP, this.onChange, this);
		}

		private onChange(e: eui.PropertyEvent) {
			console.log(this.petList.selectedItem, this.petList.selectedIndex);
			this.petList.touchEnabled = false;
		}

		private onScrollerChange() {
			let scrollV = this.game_list_scroller.viewport.scrollV;
			let thumbY = Math.abs(scrollV) / (this.game_list_scroller.viewport.measuredHeight - this.game_list_scroller.height);
			this.horizontalScrollBar.thumb.y = thumbY * (this.horizontalScrollBar.height - this.horizontalScrollBar.thumb.height);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值