Right aligning images

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

Hi guys

I'm having issues right aligning images.

Let's say the original image dimensions are 100x50 pixels. If I explicitly set the height of the image to 25 pixels it correctly resizes to 50x25 pixels. However, it seems like a container of 100x50 pixels is still present and that the resized image is centered within it.

var $image = Ti.UI.createImageView({
    image: '/img/test.png',
    height: 25,
    backgroundColor: '#ff0000',
    right: 0
});
So instead of right aligning it just stays at the center of the original image dimensions.

Anything I can do to prevent this behavior? I'm using the latest SDK.

5 Answers

Have you tried setting width: Ti.UI.SIZE? That might help...

I have not had this problem. If I take a 200x150 image and put it into a 100x75 ImageView, the ImageView is 100x75, and the image itself is resized to 100x75 so that it fits with no excess border.

Are you actually seeing a 100x50 area with background color #ff0000?

We might need to see a little more of your code. I stress little. If you can make a minimal example (a single app.js file), that would be great. And maybe a screenshot of the problem.

— answered 9 months ago by Jason Priebe
answer permalink
6 Comments
  • If you take an image of 200x150 px and scale it to a 100x75 px ImageView, you'll notice that the background color of the ImageView still is 200x150 px. If not, what are you testing on? I'm testing on iPhone/iPad with SDK version 2.1.2.GA.

    — commented 8 months ago by John Johnson

  • The image is remote by the way.

    — commented 8 months ago by John Johnson

  • Send me a minimal case (a single app.js) with a working image URL, and I'll look at it.

    — commented 8 months ago by Jason Priebe

  • Show 3 more comments

ImageView's property - right - This is relative to the view's parent.So try placing imageview in a parent view and specify its right relative to the parent view.

— answered 8 months ago by Jyoti Gupta
answer permalink
1 Comment
  • It doesn't help, unfortunately. The image is still at the center of its original dimensions.

    — commented 8 months ago by John Johnson

I did not faced this issue, but if you are facing then use work around to solve your problem, put that imageview inside a view which is at right=0 and according to your dimension. i will look for this sure and let you know and correct way.

Your Answer

Think you can help? Login to answer this question!