Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5177] Android: scaled images in ImageView are stretched if aspect ratio of view doesn't match source image.

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-09-26T15:17:32.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2011-38, Release 1.8.0
ComponentsAndroid
Labelsimageview, merged-v8, parity, scale, stage
ReporterBill Dawson
AssigneeBill Dawson
Created2011-08-30T14:06:07.000+0000
Updated2011-10-31T22:40:48.000+0000

Description

Given the attached large photo "julia.jpg" and the following app.js:
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
	title : 'Test',
	backgroundColor : '#000',
	exitOnClose : true
});

var img = Ti.UI.createImageView({
	image : "julia.jpg",
	top : 0,
	left : 0,
	width : "300dp",
	height : "100dp",
	backgroundColor : "red"
});

win.add(img);
win.open();
The aspect ratio of the image (w/h) is 0.75. The aspect ratio of the created ImageView is 3.0. If you run the app in iOS, you'll see that iOS makes a "best fit" for image, being sure to display all of it *and* at the correct aspect ratio. Our Android implementation, on the other hand, will stretch to fit the entirety of the ImageView, meaning it forces the 0.75 aspect ratio photo into a 3.0 aspect ratio, causing it to stretch horizontally and look bad.

Attachments

FileDateSize
julia.jpg2011-08-30T14:09:13.000+0000739261
timob5177.zip2011-09-21T15:52:23.000+00002356828

Comments

  1. Bill Dawson 2011-09-21

    Testing notes: The attached ugly test app (timob5177.zip) simply shows that when the aspect ratio of the bitmap and its containing ImageView are different, you get a best fit that preserves the original ratio. This is Android's "CENTER_FIT" mode which is the default. A later ticket will allow for other options. The bottom image in the test app simply shows that if you set the dimensions to "auto", you get what you'd expect: ImageView same size as scaled bitmap, aspect ratio preserved. Additionally test KitchenSink ImageView tests and TableView layout tests.
  2. Bill Dawson 2011-09-21

    Pull request ready: https://github.com/appcelerator/titanium_mobile/pull/485
  3. Don Thorp 2011-09-26

    test, review, merge.
  4. Alan Vaghti 2011-10-13

    Closing. Fix verified on Nexus One 2.2.2 with SDK 1.8.0.v20111013161411

JSON Source