一 TabBar+ViewStack实现
这个教程确实没看懂...贼麻烦...
二 RadioButton+ViewStack
在exml中拖动组件RadioButton和ViewStack
设置exml源码RadioButton的value值为0,1... 因为这个value值将会赋值给ViewStack 。并将第一个RadioButton的seleted=true,这样默认选中的第一项。
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <e:Skin class="HomeSceneSkin" width="800" height="480" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing"> <e:Group height="200" width="200" x="153" y="134"> <e:RadioButton id="rb" label="单选框" x="46" y="49" value="0" selected="true"/> <e:RadioButton y="79" label="单选框" x="46" value="1"/> </e:Group> <e:ViewStack id="viewStack" width="200" height="200" x="365" y="130" selectedIndex="1"> <e:Group width="100%" height="100%" name="视图"> <e:Button y="14" label="按钮" x="16"/> </e:Group> <e:Group width="100%" height="100%" name="视图"> <e:Button label="按钮" x="56" y="74"/> </e:Group> </e:ViewStack> </e:Skin>
ts中监听RadioButton的change事件,将value值传递给ViewStack,这样ViewStack就可以切换Group了。
private rb:eui.RadioButton; private viewStack:eui.ViewStack; public constructor() { super(); this.skinName = "HomeSceneSkin"; } public childrenCreated(){ this.rb.group.addEventListener(egret.Event.CHANGE, this.onChange, this); } private onChange(e:egret.Event){ var radioButtonGroup:eui.RadioButtonGroup = e.target; this.viewStack.selectedIndex = radioButtonGroup.selectedValue; }
原文:http://www.cnblogs.com/gamedaybyday/p/6250517.html