Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Images shifting with auto height or width

Ok, the whole url: to image: deprecation really screwed me over and I can't get back on track.

So, I've got an image I want to display in the top left corner (top: 10, left: 10). I've got it at set width and I want it to calculate the height automatically (and shrink it to fit like it use to). However, when it resizes the image it jumps from where it's supposed to be and shifts down like 100px (out of the parent view I might add)

var houseIMG = Ti.UI.createImageView({
    image: 'http://www.123.com/image.jpg',
    top: 5,
    left: 5,
    width: 130,
    height: 'auto'    
});
head.add(houseIMG);
— asked October 25th 2010 by Ryan Gartin
  • auto
  • image
  • imageview
  • tableview
0 Comments

4 Answers

  • If anyone else has the same issue: For me it worked to fix the image height, it will not be distorted. I.e.:

    var imageView = Titanium.UI.createImageView({
        image: someurl,
        width: 100,
        height: 100,
        top: 10,
        left: 10
    });
    

    Even if the image is not square, it will center itself in the specified area.

    — answered April 7th 2011 by Felix Baaken
    permalink
    0 Comments
  • J P: I'm having the exact same problem. Seems like this has not been fixed.=(

    — answered May 5th 2012 by Hakan Jacobsson Gleissman
    permalink
    0 Comments
  • I also am experiencing this same bug. I am specifying an image as follows:

            var image = Ti.UI.createImageView({
                image : imageUrl,
                width : '320',
                height: 'auto',
                clickName : 'photo'
            });
    

    The image is properly resized, but the height of the imageview remains the height of the original image size, thus there is alot of white space above and below the image.

    — answered May 30th 2012 by Timothy Fisher
    permalink
    1 Comment
    • this is true, have been working for few hours on the whitespace in ImageView end up i have to code to scale the width and height instead of using 'auto'. thanks timothy

      — commented March 25th 2013 by Daniel Lim
  • I'm not sure if this is what you're experiencing, but…

    In my current version 1.5, if you're resizing an image when putting it in an imageView (using width: x, height: 'auto'), the original height is assigned to the view, even though the image appears to be resized.

    For an example image 719x758:

    var image = Titanium.UI.createImageView({
        image: "example.jpg", left: 0, top: 0, width: 50, height: 'auto'
    });
    Titanium.API.debug("Resized width = " + image.size.width);
        // [DEBUG] Resized width = 50
    Titanium.API.debug("Resized height = " + image.size.height);
        // [DEBUG] Resized height = 758
    

    Titanium SDK 1.5, iPhone SDK 4.2
    I guess this is a bug :(

    — answered January 6th 2011 by J P
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.