Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1968] Android - View ignores width w/ left & right set.

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-04-15T03:06:52.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, defect, ignore, left, right, view, width
ReporterMike Robinson
AssigneeDon Thorp
Created2011-04-15T03:06:51.000+0000
Updated2017-03-02T18:18:02.000+0000

Description

Under the iOS implementation if you create a view with a width of 30 and then set left & right you get a view of 30 centered within the window. In Android, this is presently creating a view that stretches to fill the entire left/right space completely ignoring the width.

var win = Titanium.UI.currentWindow;
win.add(Titanium.UI.createView({

        backgroundColor: 'red',
        top: 10,
        left: 5,
        right: 5,
        width: 75,
        height: 75
    }));

Comments

  1. Don Thorp 2011-04-15

    If you want it centered, you should leave off left and right. The condition is technically undefined. We will be formalizing what should happen in undefined conditions, but averaging out the space is not what one would normally expect.

  2. Mike Robinson 2011-04-15

    I agree that this condition isn't exactly defined, however since it is performing that way on iOS I kind of expected it to transfer over (you see it in one implementation, you would normally expect it in the other).

    The challenge for me lies in the fact, I am trying to place multiple objects in a horizontal line, keeping them centered in both orientations of the window. See my example below in iOS to see what I am trying. While in this example I could create a view, add one item left, one item right, and another undefined....the challenge comes that I am trying to add 7 items horizontally. What do you recommend then?

    var win = Titanium.UI.currentWindow;
    win.add(Titanium.UI.createView({

           backgroundColor: 'red',
           top: 10,
           left: 5,
           right: 5,
           width: 25,
           height: 25
       }));
       

    win.add(Titanium.UI.createView({

           backgroundColor: 'white',
           top: 10,
           left: 5,
           right: 100,
           width: 25,
           height: 25
       }));
       

    win.add(Titanium.UI.createView({

           backgroundColor: 'blue',
           top: 10,
           left: 100,
           right: 5,
           width: 25,
           height: 25
       }));
       
  3. Don Thorp 2011-04-15

    In the future, please go through helpdesk or Q&A LH is for verified problem only and not general support.

    Simply create a View with only width and height defined, then add your other views to it defining height, width, and left. The container view will center and the other views will be relative to the container views origin.

       
       var win = Ti.UI.currentWindow;
       
       var container = Ti.UI.createView({ height : 25, width : 75});
       win.add(container);
       
       var v1 = Ti.UI.createView({left : 5, width : 25, height : 25});
       var v2 = Ti.UI.createView({left : 35, width : 25, height : 25});
       var v3 = Ti.UI.createView({left : 65, width : 25, height : 25});
       
       win.add(v1);
       win.add(v2);
       win.add(v3);
       
  4. Lee Morris 2017-03-02

    Closing as invalid.

JSON Source