Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you're relying on window.width and window.height, and these evaluate to 0 on Android (whereas they work fine on iOS). This results in your view not having any size. It's better to use Ti.Platform.displayCaps.platformWidth and Ti.Platform.displayCaps.platformHeight to get the dimensions of the screen. You'll need to be aware that this will be different on each platform, and size your views accordingly, but then you'd always have that problem.</p> <p>I've altered your code slightly so you can see it in action on both platforms.</p> <pre><code>window = Ti.UI.createWindow({ backgroundColor : 'white' }); function SuperScrollView(window) { this.scrollview = Ti.UI.createScrollView({ showVerticalScrollIndicator : true, height : Ti.Platform.displayCaps.platformHeight, width : Ti.Platform.displayCaps.platformWidth, contentHeight : 'auto' }); this.view = Ti.UI.createView({ height : 0, width : Ti.Platform.displayCaps.platformWidth }); this.addElement = function(element) { var height = this.view.height; var elementHeight = element.height; element.top = height; this.view.add(element); this.view.height += elementHeight; height = this.view.height; this.scrollview.contentHeight = height; alert(height); } this.scrollview.add(this.view); window.add(this.scrollview); } var scrollview = new SuperScrollView(window); scrollview.addElement(Ti.UI.createView({ width : 200, height : Ti.Platform.displayCaps.platformHeight + 500, backgroundColor : 'blue' })); window.open(); </code></pre> <p>EDIT: The other thing you can do is wait until the window had opened, and then add the scrollview to it once the width and height have been evaluated:</p> <pre><code>window = Ti.UI.createWindow({ backgroundColor : 'white' }); function SuperScrollView(window) { this.scrollview = Ti.UI.createScrollView({ showVerticalScrollIndicator : true, height : window.height, width : window.width, contentHeight : 'auto' }); this.view = Ti.UI.createView({ height : 0, width : window.width }); this.addElement = function(element) { var height = this.view.height; var elementHeight = element.height; element.top = height; this.view.add(element); this.view.height += elementHeight; height = this.view.height; this.scrollview.contentHeight = height; alert(height); } this.scrollview.add(this.view); window.add(this.scrollview); } window.open(); window.addEventListener('open', function(){ var scrollview = new SuperScrollView(window); scrollview.addElement(Ti.UI.createView({ width : 200, height : window.height + 500, backgroundColor : 'blue' })); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload