Titanium Community Questions & Answer Archive

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

Titanium.UI.TableView row height problem

I have the following code:

var win = Titanium.UI.currentWindow;

var tableRow = Titanium.UI.createTableViewRow({

});
var textArea = Titanium.UI.createTextArea({
    value: '   ' + win.content,
    font: {fontSize: 12},
    editable: false,
});
tableRow.add(textArea);

var contentTable = Titanium.UI.createTableView({
    style: Titanium.UI.iPhone.TableViewStyle.GROUPED,
    headerTitle: win.contentTitle,
    data: [tableRow]
});

win.add(contentTable);

I tried to add the height: auto property to it and make the tablerow dynamic, but I have ran into problems with that. My goal is to use the GROUPED tableview view to display a short paragraph, with the article title as the header.

Edit:

Using the following code, I get the result shown of the Screenshot below. The right side isn't displaying as I had hoped

var textLabel = Titanium.UI.createLabel({
    text: '   ' + win.content,
    font: {fontSize: 12},
    height: 'auto',
    width: 'auto',
    left: 8,
    top: 4,
    right: 8,
    bottom: 4
});

iphone screenshot

— asked March 15th 2010 by Ryan Sullivan
  • auto
  • height
  • iphone
  • tableview
0 Comments

12 Answers

  • Hi Ryan,

    yes you can, using the left:, top: and bottom: options, here is the code again.

    var textLabel = Titanium.UI.createLabel({
        text: '   ' + win.content,
        font: {fontSize: 12},
        height:'auto',
        width:'auto',
        left:10,
        top:5,
        bottom:5
    });
    tableRow.add(textLabel);
    
    — answered March 15th 2010 by Antonio Silveira
    permalink
    0 Comments
  • you could try using the Label object instead of a text area, or do you want the content to be editable?

    — answered March 15th 2010 by Nolan Wright
    permalink
    0 Comments
  • I did try the Label at one point, but it didn't seem to make a difference. One thought I had was that the label was possibily one line of text only

    — answered March 15th 2010 by Ryan Sullivan
    permalink
    0 Comments
  • Hi with Label you can have multiple lines as well, you just need to add the height:auto option. Here is your code using Label instead of Text Area.

    var textLabel = Titanium.UI.createLabel({
        text: '   ' + win.content,
        font: {fontSize: 12},
        height:'auto',
        width:'auto'
    });
    tableRow.add(textLabel);
    

    Hope it helped,
    Antonio

    — answered March 15th 2010 by Antonio Silveira
    permalink
    0 Comments
  • Antonio, that code helped me a ton, however, how can I add left/right padding? Right now the content goes over the left/right edges of the table cell, its even pretty close on the top/bottom too.

    — answered March 15th 2010 by Ryan Sullivan
    permalink
    1 Comment
    • trying using text wrap property

      — commented March 1st 2012 by Abrar Sair
  • Also, using the code from Antonio, the label does eventually get cutoff :(

    — answered March 15th 2010 by Ryan Sullivan
    permalink
    0 Comments
  • um

    — answered March 15th 2010 by Ryan Sullivan
    permalink
    0 Comments
  • moving to post rather than replying down here

    — answered March 15th 2010 by Ryan Sullivan
    permalink
    0 Comments
  • Hi Ryan,

    you are right, in some occasions I do have the same issue you are facing with the Text going over and out if the Label, still didn't find a solution.

    Let me know if you find something.

    Antonio

    — answered March 19th 2010 by Antonio Silveira
    permalink
    0 Comments
  • Hi Ryan,

    I finally fixed this issue of the content going over the View, I changed the width parameter with a fixed size instead of 'auto'.

    It worked for me.

    — answered March 27th 2010 by Antonio Silveira
    permalink
    0 Comments
  • But then when your app goes to landscape is that going to cause issues, I used that workaround too. however landscape looks just silly.

    — answered June 29th 2010 by Ryan Tregea
    permalink
    0 Comments
  • I think there is mention of mobile SDK 1.3.2 having 'auto' size issue somewhere…

    — answered June 29th 2010 by Peter Lum
    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.