0
votes

I have a problem with titanium 3.5.0. When I want to position my ui element based on previous element in the layout with some methods like getWidth or getTop I'm getting Nan and in the console I'm getting a warning that says:

Invalid dimension value (nan) requested. Making the dimension undefined instead.

I have scrollview and I want to arrange my item into it so what I did
this is my scrollview code

var scrollView = Ti.UI.createScrollView({
    contentWidth: 'auto',
    contentHeight: 'auto',
    backgroundColor:'#fff',
    showVerticalScrollIndicator: false,
    showHorizontalScrollIndicator: false,
    height:"100%",
    width: "100%",
    top:36.6
});  

and the scrollableview code

var view = Ti.UI.createView({
      backgroundColor:'#fff',
      borderRadius: 0,
      height: 2000,
      width: Ti.UI.FILL
    });

and then I started adding my ui element in the view

var type =Ti.UI.createLabel({
    text:"Type",
    color:label_color,
    right:207,
    left:label_p_l,
    font:{ fontFamily: customfont,fontSize:17},
    top:37.5

});   
var p_name=Ti.UI.createLabel({
    text:"Property Name",
    color:label_color,
    left:label_p_l,
    font:{ fontFamily: customfont,fontSize:17},
    top:type.getTop()+label_h+32
});

so now it's working perfectly because type has a numeric value and even I added three more element in this way and every things works perfectly after that
I have added the 4th element like this and now when I started to get Nan.

var space_Slider = Titanium.UI.createSlider({
         top:space.getTop()+space.getHeight()+15,
         min:0,
         max:1000,
         value:0,
         height:4,
         backgroundColor:"#fff",
         leftTrackImage:'/images/slider_color.png',
         rightTrackImage:'/images/slider_color.png',
         thumbImage:'/images/slider.png',

    });

now the space.getTop() starts returning Nan

Any ideas how to solve this problem?

1
Can you show some code ? - Jeroen

1 Answers

1
votes

That happens because you've specified width / top not as numeric data type, but as string. "100%", "15dp" etc

getWidth() returns numeric data types IFF you pass numeric to width parameter when constructing the element or invoking setter method.

Furthermore, if you don't specify width / top parameters during construction of the elements they will not return anything.

To get the dimensions of the element you need to add them to some container / parent view and postlayout all elements. After this is done you can ask for dimensions like this:

element.size.width