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();
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.
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.
Interesting, I missed that! Anyway, that's good to know, we should document this somehow until the said bug is fixed. Thanks!