Is there a way to take a dataset that's displayed in a typical Table view (like this, mobile web):

As display it horizontally, something more like this:

I need this to work in Mobile Web, but working on iPad would be great too.
SDK 2.1.1, OS 10.8
1 Answer
Accepted Answer
Hi Steve
Very easy - since 2.0.
You can add an attribute called layout: that has really flourished with the benefit of the changes to the sizes that have appeared.
This is an example using a scrollview with children, but you can also do this on any view or window.
Add this as the parent - think of it as the container above - light yellow background
var scrollView = Ti.UI.createScrollView({ contentHeight: 'auto', contentWidth: 'auto', height: Ti.UI.FILL, layout: 'horizontal', showHorizontalScrollIndicator: true, showVerticalScrollIndicator: true, width: Ti.UI.FILL }); win.add(scrollView);Add as many of these as you need - use loop to iterate your data of course
// hold each thumnail view var viewChild = Ti.UI.createView({ height: Ti.UI.SIZE, layout: 'vertical', width: Ti.UI.SIZE }); scrollView.add(viewChild); //image of thumbnail view var imageChild = Ti.UI.createImageView({ height: Ti.UI.SIZE, image: 'image.png', width: Ti.UI.SIZE }); viewChild.add(imageChild); // label of thumbnail view (shown under image) var lblChild = Ti.UI.createLabel({ height: Ti.UI.SIZE, text: 'Caption', width: Ti.UI.SIZE }); viewChild.add(lblChild);You can use normal
textAlign for the label to center it and use top, bottom, left & right as if they were margins - for example, changint eh label code to this;
// label of thumbnail view (shown under image) var lblChild = Ti.UI.createLabel({ height: Ti.UI.SIZE, text: 'Caption', textAlign: 'center', top: 10, width: Ti.UI.SIZE }); viewChild.add(lblChild);Will align the text to center and push the label 10 pixels DOWN from the previous view added to this parent.
The magic is the use of the layout property as mentioned. With horizontal all views are added from top left across right and until they run out of space and then move down to the next line. Using vertical things appear underneath each other.
Makes very light work laying out your work.
Your Answer
Think you can help? Login to answer this question!