Aligning in the center of a view

You must Login before you can answer or comment on any questions.

I'm trying to align some objects in the center of a view using the code:

row.height = 46;
row.layout = 'horizontal';
 
var monthLabelContainer = Ti.UI.createView({
    width:46, height:46,
    left:10,
    backgroundColor:'#CCC'
});
row.add(monthLabelContainer);
 
var assessmentsIndicatorContainer = Ti.UI.createView({
    width:7, height:34,
    left:5,
    backgroundColor:'#CCC'
});
row.add(assessmentsIndicatorContainer);
 
var monthInfoContainer = Ti.UI.createView({
    width:7, height:46,
    left:10,
    backgroundColor:'#CCC'
});
row.add(monthInfoContainer);
And this is the result: http://oi45.tinypic.com/2ur756w.jpg

As you can see, all the objects are alignes at the top of the container view.

If I remove the height of the "monthInfoContainer", everything is displayed as expected ... but I need to set an height to that object.

Am I missing something here?

1 Answer

This happens because of the horizontal layout. Try to wrap all the views in a parent view.

— answered 11 months ago by Dan Tamas
answer permalink
3 Comments
  • I thought row, being a createTableViewRow object could be the the parent view with the horizontal layout. So you say to create a new view to include all the other views and set the layout to horizontal?

    — commented 11 months ago by Luis Ferreira

  • Yes it can be te parent but because you are using layout property it has to make calculations to position the children views and results like this. Yes, create a new view, set to this view the layout and put it inside the row which doesn't have this time layout set.

    It should fix your issue :)

    — commented 11 months ago by Dan Tamas

  • I will test your suggestion, but does this means that this is a bug, I mean, using layout property on a rowView causes this it's a but or a normal behaviour? f only happens when I had the height property on the 3rd child (to the "monthInfoContainer").

    — commented 11 months ago by Luis Ferreira

Your Answer

Think you can help? Login to answer this question!