Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Help with label positioning

Hi,

I'm trying to create a table row that looks something like this: http://img72.imageshack.us/img72/3350/labels.png

I need some help :) All the labels are dynamic and I want to create some way that they always will line up.

I think I should create a view that holds the "wind" label together with the windspeed. What I can't figure out how to place is the "m/s" label. This font is smaller than the speed label so the text has to be two different labels. But if I do this the text is layered on top on eachother.

How would you structure this view?

— asked September 20th 2010 by Magnus Ottosson
  • alignment
  • iphone
  • labels
  • layout
0 Comments

3 Answers

  • something like this maybe? ( some sort of pseudo code here :) )

    view_wind( width:120);
    
    label_speed (width:60, left:0, bottom:0, textAling:right,font: {fontSize: 24} ) 
    
    label_m/s (width:60, right:0,bottom:0, textAlign:left, font: {fontSize: 12})
    
    — answered September 20th 2010 by Dan Tamas
    permalink
    0 Comments
  • When you do the

    win.add(label_speed);
    

    Or however you have it set up, instead of doing the same thing (win.add(label_ms)) have the speed label add it instead, and then set the distance from that.

    So it'd be something like…

    var win = Titanium.UI.currentWindow;
    
    var label_speed = Ti.UI.createLabel({
    text:'32',
    font:{fontSize:24},
    width:'auto',
    height:'auto',
    left:10,
    top:10
    });
    
    var label_ms = Ti.UI.createLabel({
    text:'m/s',
    font:{fontSize:12},
    width:'auto',
    height:'auto',
    left:15
    });
    
    win.add(label_speed);
    label_speed.add(label_ms);
    

    You might need to change the width of the label_speed to accomodate the m/s, but that should work for the most part :)

    — answered September 20th 2010 by Colton Arabsky
    permalink
    0 Comments
  • Thanks, I will try both the solutions and see if they work.

    — answered September 21st 2010 by Magnus Ottosson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.