Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24428] Android: Titanium.UI.View.center setter does not work

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-03-29T14:48:50.000+0000
Affected Version/sRelease 6.0.0, Release 6.0.1
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsqe-6.1.0
ReporterYellowcube
AssigneeEric Merriman
Created2017-02-08T03:10:18.000+0000
Updated2017-04-04T14:37:20.000+0000

Description

i having the issue on getting the value from imageviewl.center.x or y from ti.sdk 6 and above on android project. But when i try run my project on the ti.sdk 5 and it worked. please help. *sample code for XML* *sample code in controller* $.Fcontainer.addEventListener('open', setup); function setup() { $.croppedPhoto.width = '400'; $.croppedPhoto.height = '400'; $.croppedPhoto.zIndex = 0; $.previewImage.image = '/images/default_img/default_exhibitor.png'; $.previewImage.image.quality = '1.0'; centerPhoto(); } s function centerPhoto() { console.log("centering the photo"); $.previewImage.center = { x : $.croppedPhoto.width / 2, y : $.croppedPhoto.height / 2 }; } function touchStart(e){ console.log("center.x --------------------------"+$.previewImage.center.x ); console.log("center.y --------------------------"+$.previewImage.center.y ); }

Attachments

FileDateSize
Screenshot 2017-02-09 11.08.31.png2017-02-09T03:16:04.000+000045461
Screenshot 2017-02-09 11.11.05.png2017-02-09T03:16:08.000+000017182

Comments

  1. Sharif AbuDarda 2017-02-08

    Hello, Please attach a sample code that we can test to reproduce the issue. Thanks.
  2. Sharif AbuDarda 2017-02-09

    Hello, "This is an input property for specifying where the view should be positioned, and does not represent the view's calculated position", http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-property-center. So, you have to define the X and Y, or else they are undefined. Take the below code as an example
       Ti.UI.backgroundColor = 'white';
       var win = Ti.UI.createWindow();
       var image = Ti.UI.createImageView({
           image : 'KS_nav_ui.png',
       });
       
       image.addEventListener('click', function(e) {
           Ti.API.info("You clicked the image");
           console.log("center.x --------------------------" + image.center.x);
           console.log("center.y --------------------------" + image.center.y);
       
       });
       win.add(image);
       win.open();
       
    This response in error as X and Y is undefined. Now, define
       center : {
       
               x : '200',
       
               y : '200'
       
           }
       
    in imageview and see the right response. Thanks.
  3. Yellowcube 2017-02-16

    Hi Sharif AbuDarda, In my code right, i try to assign the imageview center x and y after the imageview object is created. Example as from this tutorial [https://books.google.com.sg/books?id=7PmoCwAAQBAJ&pg=PA171&lpg=PA171&dq=appcelerator+change+image+center+x&source=bl&ots=u4xn1AtC_Q&sig=DcIIwCDF0ebNtwzKYgIG31lRnTM&hl=en&sa=X&ved=0ahUKEwi68K-m25PSAhXML48KHVUuBYcQ6AEIPTAG#v=onepage&q=appcelerator%20change%20image%20center%20x&f=false] it worked if you assign the imageview center x and y while you create the object, but it doesnt worked if you try to assign it after the object was created. what you can try is change the center x and y after you initlal the value ofter imageview and console out the value. The X and Y value will not able to change after you first initial when the object was created. But in SDK 5 is worked if i change the value after the object was created. try to run the sample code below in SDK 5 and 6 than compare the console as show as below, then you will know that the imageview center x and y is not changeable when run in SDK 6 EXAMPLE CODE // this sets the background color of the master UIView Titanium. //UI.setBackgroundColor('#fff'); // //create root window // var win1 = Titanium.UI.createWindow({ title: 'Funny Faces', backgroundColor: '#000' }); //this will determine whether we load the 4 funny face //images or whether one is selected already var imageSelected = false; //the 4 image face objects, yet to be instantiated var image1; var image2; var image3; var image4; var imageViewMe = Titanium.UI.createImageView({ image: '/assets/images/test3.png', width: device_width(), height: 'auto', zIndex: 0, left: 0, top: 0, zIndex: 0, center: { x: Ti.Platform.displayCaps.platformWidth/2, y: Ti.Platform.displayCaps.platformWidth/2 } }); win1.add(imageViewMe); var imageViewFace = Titanium.UI.createImageView({ image: '/assets/images/top_Global_Knowledge_1.png', left: 0, top: 0, width: device_width(), height: device_width(), zIndex: 1 }); console.log('initial imageViewMe.center.x :'+imageViewMe.center.x); console.log('initial imageViewMe.center.y :'+imageViewMe.center.y); imageViewMe.center = { x:( '1'), y:( '1'), }; console.log('change imageViewMe.center.x :'+imageViewMe.center.x); console.log('change imageViewMe.center.y :'+imageViewMe.center.y); win1.add(imageViewFace); win1.open(); function device_height() { var dWidth, dHeight = null; dWidth = (Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.logicalDensityFactor); dHeight = (Ti.Platform.displayCaps.platformHeight / Ti.Platform.displayCaps.logicalDensityFactor); return (dWidth < dHeight) ? dHeight : dWidth; }; /**GET DEVICE WIDTH**/ function device_width() { var dWidth, dHeight = null; dWidth = (Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.logicalDensityFactor); dHeight = (Ti.Platform.displayCaps.platformHeight / Ti.Platform.displayCaps.logicalDensityFactor); return (dWidth < dHeight) ? dWidth : dHeight; }; console.log('TI Y '+Ti.Platform.displayCaps.platformHeight); console.log('TI X '+Ti.Platform.displayCaps.platformWidth); imageViewFace.addEventListener('touchmove', function (e) { //console.log('e.x :' + e.x ); //console.log('e.y :' + e.y ); // imageViewMe.left = e.x; // imageViewMe.top = e.y; }); imageViewFace.addEventListener('touchstart', function (e) { //imageViewMe.ox = e.x - imageViewMe.center.x; //imageViewMe.oy = e.y - imageViewMe.center.y; // console.log('touchstart e.x :' + e.x ); // console.log('touchstart e.y :' + e.y ); // console.log('touchstart imageViewMe.center.x :'+imageViewMe.center.x); // console.log('touchstart imageViewMe.center.y :'+imageViewMe.center.y); // imageViewMe.ox = e.x - imageViewMe.center.x; // imageViewMe.oy = e.y - imageViewMe.center.y; }); imageViewFace.addEventListener('touchmove', function (e) { var halfp = (Ti.Platform.displayCaps.platformWidth/2); var test = e.x - imageViewMe.center.x; console.log('< : ' + test); imageViewMe.left = e.x - imageViewMe.center.x; imageViewMe.top = e.y - imageViewMe.center.y; }); imageViewFace.addEventListener('pinch', function(e) { imageViewMe.ox = e.x - imageViewMe.center.x; imageViewMe.oy = e.y - imageViewMe.center.y; imageViewMe.height = device_width() * e.scale; imageViewMe.width = device_width() * e.scale; });
  4. Sharif AbuDarda 2017-02-23

    Hello, This is a real bug in the platform. Take a look at the below code.
       Ti.UI.backgroundColor = 'white';
       
       var win = Ti.UI.createWindow();
       
       var view = Ti.UI.createView({
           top : 10,
           backgroundColor : 'red',
           height : "50dp",
           width : "100dp"
       });
       
       view.addEventListener('click', function(e) {
       
           Ti.API.info("You clicked the image");
           view.center = {
       
               x : '50dp',
       
               y : '50dp'
       
           };
       
       });
       
       win.add(view);
       
       win.open();
       
    In SDK 6.0.x+ View property center work if you assign the view center x and y while you create the object, but it doesn't worked if you try to assign it after the object was created. This was working fine in SDK 5.5.1.GA.
  5. Zakhar Zhuravlev 2017-03-07

    Why this issue still isn't added to any Release? Release 6.0.3 would be great. It's annoying regression.
  6. Zakhar Zhuravlev 2017-03-07

    "In SDK 6.0.x+ View property center work if you assign the view center x and y while you create the object, but it doesn't worked if you try to assign it after the object was created." It's not true! It doesn't work even if you assign center property during creating of object.
  7. Mick 2017-03-18

    also happens for left and top properties for the view when using postlayout eventlistener. This is a really bad bug guys, please fix this ASAP.
  8. Gary Mathews 2017-03-22

    Since the other ticket also fixes a different issue, I made a separate PR for this. master: https://github.com/appcelerator/titanium_mobile/pull/8904
  9. Josh Longton 2017-04-04

    {noformat} Mac OS Version : 10.12.3 Appc CLI : 6.1.0 Appc NPM : 4.2.9-1 Node : v4.6.0 Device: Nexus 5x(6.0.1) Pixel XL(7.1.2) Emulator: (6.0), (4.4.2) {noformat} Using above env passed FR. After merge, the changes are present in SDK 6.1.0.v20170401095755. *Closing*

JSON Source