Titanium JIRA Archive
Alloy (ALOY)

[ALOY-286] Alloy - ImageView is not working in Android

GitHub Issuen/a
TypeBug
PriorityCritical
StatusResolved
ResolutionFixed
Resolution Date2012-09-20T16:26:01.000+0000
Affected Version/s2012 Sprint 19
Fix Version/s2012 Sprint 19, Release 3.0.0
ComponentsRuntime, XML
Labelsalloy
ReporterPedro Enrique
AssigneeUnknown
Created2012-09-20T15:10:05.000+0000
Updated2018-03-07T22:26:10.000+0000

Description

Problem

Image views are not displaying images in Android

Alloy app

The _logo.png_ is an image in _assets_ folder **index.js**
function doClick(e) {  
    alert($.label.text);
}
$.logo.image = "logo.png";
$.index.open();
**index.jss**
".container": {
	backgroundColor:"white"
},
"Label": {
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	color: "#000"
} 
**index.xml**
<Alloy>
	<Window class="container">
		<Label id="label" onClick="doClick">Hello, World</Label>
		<ImageView id="logo" />
	</Window>
</Alloy>
But this in app.js works: **app.js**
var win = Ti.UI.createWindow({
    fullscreen: true
});
win.add(
    Ti.UI.createImageView({
        image: 'logo.png'
    })
);
win.open();

Comments

  1. Tony Lukasavage 2012-09-20

    A quick fix is to prefix your image paths with a "/", so make it "/logo.png". This works on all platforms with Alloy. I'm going to investigate further to see why this isn't working for Alloy.
  2. Tony Lukasavage 2012-09-20

    Pedro, this is happening because you're trying to access the images with relative paths. It works in standard Titanium because both your app.js and the image file are in the same folder. It does not work in Alloy because index.js is in Resources/alloy/controllers and the image is in Resources. For whatever reason, iOS and Android handle these relative paths differently. iOS makes the "relative" path relative to Resources where Android makes it relative to the folder of the currently executing file. Not sure what Mobileweb does. This will need some serious digging to figure out where the differences are, and what the expected behavior should be for all platforms.
  3. Tony Lukasavage 2012-09-20

  4. Pedro Enrique 2012-09-20

    Interesting, I missed that! Anyway, that's good to know, we should document this somehow until the said bug is fixed. Thanks!

JSON Source