feathers组件宽高如何确定?

项目中需要确定 feathers组件的宽高,但是怎么读取都是0 

翻阅 api:



width property 

width:Number[override]

The width of the component, in pixels. This could be a value that was set explicitly, or the component will automatically resize if no explicit width value is provided. Each component has a different automatic sizing behavior, but it's usually based on the component's skin or content, including text or subcomponents.

Note: Values of the width and height properties may not be accurate until after validation. If you are seeing width or height values of 0, but you can see something on the screen and know that the value should be larger, it may be because you asked for the dimensions before the component had validated. Callvalidate() to tell the component to immediately redraw and calculate an accurate values for the dimensions.


Implementation 
    public function get width():Number
    public function set width(value:Number):void

See also


所以  ,我们在把 组件添加到 显示列表后,立即调用validate()方法,把组件进行验证,则可确定宽高

如下:

confirmBtn = new feathers.controls.Button();
confirmBtn.label = "Game Over!";
addChild(confirmBtn); //为什么feathers 组件width == 0   ||| 
confirmBtn.validate(); //添加到显示列表后,立即验证,则可得到组件的实际宽高,否则有可能读不到
confirmBtn.x = this.width * 0.5 - confirmBtn.width * 0.5;;
confirmBtn.y = this.height * 0.5 - confirmBtn.height * 0.5;

 这样我们就可以设定了,注意如果用到viewPort ,则居中显示尤为重要!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值