[TIMOB-5177] Android: scaled images in ImageView are stretched if aspect ratio of view doesn't match source image.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-09-26T15:17:32.000+0000 |
Affected Version/s | Release 1.8.0 |
Fix Version/s | Sprint 2011-38, Release 1.8.0 |
Components | Android |
Labels | imageview, merged-v8, parity, scale, stage |
Reporter | Bill Dawson |
Assignee | Bill Dawson |
Created | 2011-08-30T14:06:07.000+0000 |
Updated | 2011-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
File | Date | Size |
---|---|---|
julia.jpg | 2011-08-30T14:09:13.000+0000 | 739261 |
timob5177.zip | 2011-09-21T15:52:23.000+0000 | 2356828 |
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.
Pull request ready: https://github.com/appcelerator/titanium_mobile/pull/485
test, review, merge.
Closing. Fix verified on Nexus One 2.2.2 with SDK 1.8.0.v20111013161411