1. 程式人生 > >Egret之egret.ScrollView

Egret之egret.ScrollView

horizon 方案 小遊戲 etc height eight play 初始 容器

由於在微信小遊戲中,無法使用eui框架(即無法使用eui.Scroller) . 還好egret框架內提供了egret.ScrollView可以完美替代.

一 : 申明及初始化

private _scrollview : egret.ScrollView = null;
this._scrollview = new egret.ScrollView();

二:選擇顯示容器

this._scrollview.setContent( this._list_con );

二-1 : private _list_con : egret.DisplayObjectContainer = null;

三:設置位置及SIZE

this._scrollview.x = ( ( this._UI_SZ.x - this._content_bg.width ) >> 1 ) + 13;
this._scrollview.y = 101.5;
this._scrollview.width = this._content_size.x;
this._scrollview.height = this._content_size.y;

四:設置滾動方案

this._scrollview.verticalScrollPolicy = "on";
this._scrollview.horizontalScrollPolicy = "off";

四-1 : 此代碼為在豎直方向上滾動 , 在水平方向上不滾動

五:加入到顯示容器

this.addChild( this._scrollview );

六:手動設置滾動的距離

this._scrollview.scrollTop = 0;

Egret之egret.ScrollView