ScrollView not working with dynamically loaded image?

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

I have a ImageView in which i load an image taken with the camera. But since this image view can take up quite some height, i thought that it would be better to place the ImageView inside a ScrollView. So that the user can pan through the image instead.

So i created all those windows, but for some reason the ScrollView doesn't work when the image is loaded.

var viewCamImage = Ti.UI.createScrollView({
        layout: 'vertical',
        width: '80%',
        height: '200dp'
    });
 
    var camImage = Ti.UI.createImageView({
        top: '0dp',
        width: '100%',
        height: 'auto'
    });
    viewCamImage.add(camImage);
    win.add(viewCamImage);
The image is placed inside the ImageView, and i can clearly see that the image is larger than the '200dp' specified in the height property of the ScrollView. But for some reason the ScrollView isn't working. I can't scroll down...

It does work however, when i place textfields inside the ScrollView. It's just that it doesn't work with my ImageView. Anyone any idea how to solve this problem..??

1 Answer

Accepted Answer

Hi David

Add these to your scrollView

contentWidth: 'auto',
contentHeight: 'auto',
showVerticalScrollIndicator: true,
showHorizontalScrollIndicator: true,
So yours becomes
var viewCamImage = Ti.UI.createScrollView({
  contentWidth: 'auto',
  contentHeight: 'auto',
  showVerticalScrollIndicator: true,
  showHorizontalScrollIndicator: true,
  layout: 'vertical',
  width: '80%',
  height: '200dp'
});
This tells the scroll view how to handle the content that sits inside it. You can play with the values, but these work in most cases.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
2 Comments
  • Also consider using the new SIZE and FILL constants.

    For example;

    var camImage = Ti.UI.createImageView({
      top: '0dp',
      width: '100%',
      height: 'auto'
    });
    Could become
    var camImage = Ti.UI.createImageView({
      top: '0dp',
      width: Ti.UI.SIZE,
      height:Ti.UI.SIZE
    });
    If you want the imageview to be the size of the image, or
    var camImage = Ti.UI.createImageView({
      top: '0dp',
      width: Ti.UI.FILL,
      height:Ti.UI.SIZE
    });
    To match your 100% choice in your code.

    SIZE = only big enough to fit the child, or chidlren if you are nesting FILL = use the most space available to fill up the parent.

    These work for Height and WIDTH

    — commented 10 months ago by Malcolm Hollingsworth

  • Thanks guys for the tips and solution!

    — commented 10 months ago by david david

Your Answer

Think you can help? Login to answer this question!