Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1775] Ti.UI.View center property not implemented on Android, no warning in documentation

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2018-08-02T22:06:32.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, apidoc, center, feature, missing, patch, properties, ui, ui.view, view
ReporterRalf Pfeiffer
AssigneeEric Merriman
Created2011-04-15T03:01:56.000+0000
Updated2018-08-02T22:06:38.000+0000

Description

Docs for Ti.UI.View and its fellow view types lists a center property:

https://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.View-object"> https://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI...

center   object      a dictionary with properties x and y to indicate the center of the views position relative to the parent view

This property is very useful for positioning things under, over, or next to other views, however it appears to be unimplemented on Android.

/*
 * This code demonstrates the missing center property on Android...
 * on iPhone shows: "160, 230"
 * on Android shows: "wtf? null"
 */

var window = Titanium.UI.createWindow({
});
var button = Titanium.UI.createButton({
    title: "Where am I?",
    width: 200,
    height: 50
});
button.addEventListener('click', function() {
    var center = button.center;
    var msg;
    Ti.API.info('center: ' + center);
    if (center) {
        Ti.API.info('center.x: ' + center.x);
        Ti.API.info('center.y: ' + center.y);
        msg = center.x + ', ' + center.y;
    } else {
        msg = 'wtf? ' + center;
    }
    button.title = msg;
});
window.add(button);
window.open();

Changing it to check an actual 'View' object makes no difference; View, Button, and Label have all been tested, and there's no sign of a 'center' property implementation in the titanium_mobile/android source tree.

Comments

  1. Brion Vibber 2011-04-15

    I've implemented a getter, it seems to work for me:

    http://github.com/brion/titanium_mobile/commits/android-center">http://github.com/brion/titanium_mobile/commits/android-center
    http://github.com/brion/titanium_mobile/commit/f0c7f7d64f0d58ded647db21a9198a1eb105d830"> http://github.com/brion/titanium_mobile/commit/f0c7f7d64f0d58ded647...

  2. Brion Vibber 2011-04-15

    Assigning to Don for review per IRC.

  3. Jeff Haynie 2011-04-15

    (from [5c491f17f7d9592942ae24af18ac4a494ccfee4b]) [#1775 state:fixed-in-qa] Implement getter for View.center property on Android http://github.com/appcelerator/titanium_mobile/commit/5c491f17f7d9592942ae24af18ac4a494ccfee4b"> http://github.com/appcelerator/titanium_mobile/commit/5c491f17f7d95...

  4. Thomas Huelbert 2011-04-15

    1.6 G1, 2.2 simulator. iOS 4.1 and 3.2.2. 1.4.1.ec5d6d

  5. Pedro Enrique 2012-03-11

    Reopening for parity. In both iOS and Android the following works:
       view.center = { x: 100, y: 100 };
       
    But this only works on iOS and break on Android:
       view.setCenter({x: 100, y: 100});
       
    Edit: Tested on the latest Titanium 2.0.0 (2012/03/10 10:33 018abda) SDK
  6. Eric Merriman 2018-08-02

    With slightly modified code (since the property starts as "undefined" and only reads once set:
       var window = Titanium.UI.createWindow({
       });
       var button = Titanium.UI.createButton({
       title: "Where am I?",
       width: 200,
       height: 50
       });
       button.addEventListener('click', function() {
       button.center = {x: 17,y: 19};
       var center = button.center;
       var msg;
       Ti.API.info('center: ' + center);
        
        
       if (center) { Ti.API.info('center.x: ' + center.x); Ti.API.info('center.y: ' + center.y); msg = center.x + ', ' + center.y; } else { msg = 'wtf? ' + center; }
       button.title = msg;
       });
       window.add(button);
       window.open();
       
    The setting of center moves the item, and the console output shows the values as expected on Android:
       [INFO]  center.x: 17
       [INFO]  center.y: 19
       
    Unless I am misunderstanding, I am closing as invalid. Please reopen if I am mistaken.

JSON Source