scrollView not visible when height=
hi,
i open a window with this code:
var win = Ti.UI.currentWindow;
var homeBtnBerechnung = Ti.UI.createButton({
title: "Berechnung Modernisierung"
});
homeBtnBerechnung.addEventListener("click", function(e){
var win = null;
win = Ti.UI.createWindow({
width:"auto",
height:"auto",
title:"Ermittlung Altanlage",
url:"ermittlungAltanlage.js",
navBarHidden:false
});
win.open();
});
win.add(homeBtnBerechnung);
the content of the window is in this file
ermittlungAltanlage.js
Ti.include("../Typo.js");
var win = Ti.UI.currentWindow;
var scrollView = Ti.UI.createScrollView({
width:"auto",
height:"auto",
backgroundColor:"#c7cccf",
layout:"vertical",
scrollType:"vertical"
});
var content = Ti.UI.createView({
height:"auto",
width:Ti.Platform.displayCaps.platformWidth - 20,
borderWidth:1,
borderColor:"#ddd",
borderRadius:10,
layout:"vertical",
backgroundColor:"#fff"
});
content.add(buildingType());
scrollView.add(content);
win.add(scrollView);
setLabel(17, "#555555");
function buildingType()
{
var btnBar = Ti.UI.createButtonBar();
var btnRight = Ti.UI.createButton();
var btnLeft = Ti.UI.createButtonBar();
var view = Ti.UI.createView();
label.text = "Gebäudeart";
label.left = 20;
label.top = 15;
view.add(label);
return view;
}
but after deploying all i see is en empty window. all heights are set to "auto", so why doesn't it adjust to the content?
edit:
acutually, scrollView is visible, but the content is not.
3 Answers
-
Accepted Answer
Hi again, Marcin
You don't need to know the height of contentHeight, as this will be calculated automatically from the height of each object that you add to it.
-
Marcin
Just to note, when posting code it is really helpful from the helpers' perspective if it runs when it is pasted verbatim into a project. This can also increase your chances of getting an answer.
Firstly, you can reduce the size, and consequently complexity, of your code by relying more on property defaults. With this in mind, the view dimensions set to 'auto' are unnecessary. On a similar theme,
var win = Ti.UI.createWindow({});
can be used in place of:
var win = null;
Also, you will save yourself a lot of confusion at some point in the future if you use absolute include statements. Thus, change:
Ti.include("../Typo.js");
to
Ti.include("/Typo.js");
where the leading forward slash is equivalent to the Resources directory.
I think the issue with your code is that where a vertical layout is used for the scrollView, the height needs to be explicitly set on its child views, or else the contentHeight cannot be calculated by the underlying system.
Hope this helps. Let me know how you get on. :)
-
hi hal,
thanks for the tips, much appreciated. :)
so the scrollview doesn't stretch to fit the content? but what happens, when i don't know the height of contentHeight?
thanks!