Image scale dimension weird on Android

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

Hi,

I have a imageView with a size of 244 height and auto width.

var photosView = Ti.UI.createImageView({
        left:           0,
        right:          0,
        height :        244,
        top :           40,
        visible:        true,
 
        canScale:       false,
        image:          images[win.openId].imageURL,
        zIndex:         1
    });
When a portrait image is shown on the iPhone, the aspect fill is good, on the android it's stretched.

The image is an URL image of the internet.

Is there a workaround for it?

Thank you in advance.

Louis

— asked 2 years ago by Louis van de Wiele
1 Comment
  • Also tried borderRadius or set canScale to true, but on Android, still a streched image.

    — commented 2 years ago by Louis van de Wiele

2 Answers

Accepted Answer

Try setting the actual width to auto, rather than letting Titanium do it itself (Which, on Android, it seems very bad at doing.) Such as:

var photosView = Ti.UI.createImageView({
        left:           0,
        right:          0,
        height :        244,
        top :           40,
        visible:        true,
        width:          'auto',
        canScale:       false,
        image:          images[win.openId].imageURL,
        zIndex:         1
    });

— answered 2 years ago by Colton Arabsky
answer permalink
3 Comments
  • Hi Colton, Thank you.

    It's stretching even more. Tried using left, right and width together, or also alone with width.

    The image i'm using to test: http://www.flhost.nl/5_201107221421145754_1347.jpg

    I will try to simulate it in a new stand alone app.

    — commented 2 years ago by Louis van de Wiele

  • Hi,

    got it working with a workaround. I need to use top, bottom, left and right. Not the height property.

    Then i add the imageView to a normal view and voila ;)

    var view = Ti.UI.createView({
        top: 10,
        height: 244,
        left: 0,
        right: 0
        });
    photosView = Ti.UI.createImageView({
                left:           0,
                right:          0,
     
                top:            0,
                bottom:         0,
                width:          'auto',
                canScale:       true,
                image:          'http://www.flhost.nl/5_201107221421145754_1347.jpg',
            });
     
            view.add(photosView);
    win.add(view);
    All thanks for your help!

    — commented 2 years ago by Louis van de Wiele

  • Above workaround worked great for me

    — commented 1 year ago by Matthew Jones

Don't use left and right properties together. If you, for example, define "View" with properties left:0, right:0 and width: 10, that will make "View"'s width '100%' effectively and real defined width won't be respected. Use just one of those properties, also top and bottom properties have same issue.

Your Answer

Think you can help? Login to answer this question!