EUI库 - EXML
生活随笔
收集整理的這篇文章主要介紹了
EUI库 - EXML
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
| ? | EXML是可以運行時加載解析的 |
| ? | <e:Skin?class="skins.ButtonSkin"?states="up,down,disabled"?minHeight="50"?minWidth="100"?xmlns:e="http://ns.egret.com/eui"> <e:Image?width="100%"?height="100%"?scale9Grid="1,3,8,8"?alpha.disabled="0.5"source="button_up_png"source.down="button_down_png"/> <e:Label?id="labelDisplay"?top="8"?bottom="8"?left="8"?right="8"size="20"?fontFamily="Tahoma?'Microsoft?Yahei'"verticalAlign="middle"?textAlign="center"?text="按鈕"?andtextColor="0x000000"/> <e:Image?id="iconDisplay"?horizontalCenter="0"?verticalCenter="0"/> </e:Skin> 描述了一個按鈕的皮膚class 是 skins.ButtonSkin alpha.disabled = 0.5source.downtextAlign left center right (和horizontalAlign的布局值一樣) |
| 直接引用Exml文件 | 假設(shè) exml的要節(jié)點是 Skin這時可以直接這樣var button = new eui.Button();button.skinName = "resource/skins/ButtonSkin.exml"this.addChild( button ) ; |
| 動態(tài)加載Exml文件 | 如果 exml的根節(jié)點不是 SkinEXML.load( "skins/ButonSkin.exml", this.onLoaded, this ) ;private onLoaded( clazz:any, url:string ):void{? ?var button = new eui.Button();? ?button.skinName = clazz ;? ?this.addChild( button ) ;} |
| 嵌入EXML到代碼 | var?className?=?"skins.ButtonSkin";var?exmlText?=?`<e:Skin?class="${className}"?states="up,over,down,disabled"?xmlns:s="http://ns.egret.com/eui">?...</e:Skin>`;var button = new eui.Button();? ?button.skinName =?exmlText? ;? ?this.addChild( button ) ; 或者先用HttpRequest去加載然后用EXML.parse( exmlText ) 去解析,直接可以返回類定義 |
| ? | <e:Group?class="app.MyGroup"?xmlns:e="http://ns.egret.com/eui"> </e:Group> 和下面代碼含義一樣:module?app?{ export?class?MyGroup?extends?eui.Group?{ public?constructor(){super();}}} 注意一定要加 class |
| 最基本的圖片 | <e:Image source="image/button_up.png" x="10"/><e:Image source="image/button_up.png" x="10"> <e:scale9Grid> <e:Rectangle x="10" y="10" width="45" height="35"/> </e:scale9Grid> |
| id屬性 | 這個id屬性與HTML中的id并不是一回事,它的結(jié)果相當于給解析后的類聲明了一個公開變量 我們可以在節(jié)點上聲明一個id屬性,注意這個id屬性與HTML中的id并不是一回事,它的結(jié)果相當于給解析后的類聲明了一個公開變量。例如: - <e:Group class="app.MyGroup" xmlns:e="http://ns.egret.com/eui"> <e:Image id="iconDisplay" /> </e:Group> 等價于: - module app { - export class MyGroup extends eui.Group { - public iconDisplay:eui.Image; - public constructor(){- super();- var image = new eui.Image();- this.addChild(image);- this.iconDisplay = image;- }- }- } |
| 語法糖 | <e:Image source="image/button_up.png" x="10" scale9Grid="10,10,45,35" /> <e:Image source="image/button_up.png" width=“100%” height="100%" />等價于:var?image?=?eui.Image();image.source?=?"image/button_up.png";image.percentWidth?=?100;image.percentHeight?=?100; 節(jié)點默認屬性我們已經(jīng)知道了復雜屬性節(jié)點的聲明方式,要先顯式聲明一個屬性名稱的節(jié)點,內(nèi)部再跟上要賦值的節(jié)點。這里還有一個類似語法糖的寫法,eui庫內(nèi)的組件,通常都會有一個默認屬性,如果子節(jié)點是賦值給父節(jié)點的默認屬性,那么可以省略屬性名節(jié)點。我們來看一個例子: <e:Scrollerclass="app.MyScroller"xmlns:e="http://ns.egret.com/eui"> <e:viewport> <e:Group/> </e:viewport> </e:Scroller> 這個例子中,我們將Group實例賦值給了一個滾動容器Scroller的viewport屬性。由于viewport是Scroller的默認屬性,因此我們可以直接省略<e:viewport>節(jié)點,改成如下寫法: <e:Scrollerclass="app.MyScroller"xmlns:e="http://ns.egret.com/eui"> <e:Group/> </e:Scroller> 默認屬性除了支持省略屬性名節(jié)點外,若默認屬性的類型是一個數(shù)組,還可以省略Array節(jié)點。其實添加子項也只是省略默認屬性的一種特例,因為容器的默認屬性是elementsContent,類型正是數(shù)組。最開始添加子項的那個例子完整寫法如下: <e:Groupclass="app.MyGroup"xmlns:e="http://ns.egret.com/eui"> <e:elementsContent> <e:Array> <e:Image/> </e:Array> </e:elementsContent> </e:Group> 當然,我們直接用最簡潔的省略默認屬性寫法即可。 |
| 內(nèi)部類 | 除了皮膚,ItemRenderer也是一個典型的使用率很高且不復用的組件。我們現(xiàn)在也可以直接內(nèi)嵌ItemRender的皮膚到List節(jié)點中: |
| 視圖狀態(tài) | 也算是語法糖的一種 在根節(jié)點上,我們聲明了視圖狀態(tài)名稱列表?states="up,over,down,disabled",它表示這個皮膚具有up,over,down,disabled這四種狀態(tài),當皮膚的currentState屬性被邏輯組件設(shè)置為這四個狀態(tài)之一時 1.添加移除對象, includeIn之外,還有一個excludeFrom 2.設(shè)置屬性。 textColor.down="0x009aff" |
轉(zhuǎn)載于:https://www.cnblogs.com/jason-beijing/p/7295890.html
總結(jié)
以上是生活随笔為你收集整理的EUI库 - EXML的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LiberOJ #6210. 「美团 C
- 下一篇: C语言学习笔记 (005) - 二维数组