Tôi đang làm việc này và gặp sự cố với mã ở trên bằng cách sử dụng 3.2.2, thử nghiệm trên Android. Các lần thử khác nhau sẽ chỉ cho tôi 1, 0 hoặc SIZE cho giá trị chiều rộng và chiều cao. Điều này sử dụng một imageView, nhưng sau đây được cho tôi tất cả mọi thứ tôi cần trong môi trường này. Tôi cũng đang sử dụng sự kiện tải thay vì postLayout. Hy vọng rằng điều này sẽ giúp một ai đó.
$.map.image = 'http://getyourownimage.com/dev/8fac94c6-872b-4bda-a56a-7dba09188c66.png';
$.map.zIndex = 1;
$.map.width = 'auto';
$.map.height = 'auto';
$.map.addEventListener('load',function(e){
var rect = $.map.getRect();
Ti.API.info(rect.width); //actual width of imageView
Ti.API.info(rect.height); //actual height of imageView
Ti.API.info($.map.getWidth()); //returns auto/SIZE, doesn't work
Ti.API.info($.map.getHeight()); //returns auto/SIZE, doesn't work
Ti.API.info($.map.toImage().width); //some scaled value, not useful
Ti.API.info($.map.toImage().height); //some scaled value, not useful
Ti.API.info($.map.toBlob().width); //image original/full size width
Ti.API.info($.map.toBlob().height); //image original/full size height
alert('rectX:'+rect.width+',rectY:'+rect.height+',mapGW:'+$.map.getWidth()+',mapGH:'+$.map.getHeight()+',tiX:'+$.map.toImage().width+',tiY:'+$.map.toImage().height+',tbX:'+$.map.toBlob().width+',tbY:'+$.map.toBlob().height);
});
Nguồn
2014-04-01 22:37:16
Nó không hoạt động với phiên bản sdk 2.1.1.GA –