imageView has whitespaces

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

I have an imageView and assigning(reteriving URL from server) 10 images to that view in loop. I haven't define any height and width of imageView. The problem is that when page loads some images have whitespaces above&below that image. Why..??

2 Answers

I've never tried an ImageView without a height and width (how are you using it without height and width anyway?).

I suspect that not all your images have the same dimensions. Maybe Titanium is sizing the ImageView based on the size of the first image.

Imagine if the first image was 320x240. Then the next image was 320x220 -- you would have 10 pixels of empty space at the top and bottom.

One other thing: if cross-platform is a concern, you should know that on Android, the ImageView will stretch your images to fit the box, while on iOS, it will proportionally resize the image.

— answered 12 months ago by Jason Priebe
answer permalink
7 Comments
  • so Jason, what size should I give for height and width?

    — commented 12 months ago by Lokesh Gupta

  • When I have setted height:'auto',width:'auto', then at first time some images are appearing very small on the other hand some are actual size. Any alternative solution..?

    — commented 12 months ago by Lokesh Gupta

  • And yes you are right, all images are of different sizes.

    — commented 12 months ago by Lokesh Gupta

  • Show 4 more comments

There's not a one-line solution that I can give you that's going to work for you. This is highly dependent on your application and things like this:

  • are your images built into the app, or are they coming from a server?
  • do the images all have approximately the same aspect ratio?
  • do you need this to work on iOS and android?
  • what is your UI layout like for the window in question? Is the imageview essentially full-screen or is it a smaller part of the interface?

If you have radically different image aspect ratios, you're going to have to do some dynamic sizing of the imageview to accomodate those sizes.

You may need to look at how you're getting the images to your application, and send width, height information along with your images.

I do that in my app -- I have a scrollableview that contains a series of imageviews. The user can swipe through the images. My app loads its images from a JSON feed, in which I provide the image URL along with the width and height of each image. I use that width and height to compute the aspect ratio, which helps me size my imageview accordingly.

Your Answer

Think you can help? Login to answer this question!