Titanium/Appcelerator 图片不会显示在 Android

Titanium/Appcelerator images will not show on Android

我带着令人沮丧的冒险故事回来了。这次是关于钛 android 一侧的图像。

长话短说,我无法为 android 显示任何图像,无论是背景图像还是 imageView 对象中的纯图像。

我将提供我正在尝试的代码,并保持它非常小和简单,以便它可以很容易地复制用于我们所有的测试目的。

代码:

尝试 #1 以编程方式创建视图和图像:

index.js

var header = Ti.UI.createImageView({
    width: 300,
    image: '/images/header.png',
    width: 300
});

var win = Ti.UI.createWindow({
    backgroundColor: 'white',
    height: Ti.UI.FILL,
    title: 'test',
    width: Ti.UI.FILL
});

win.add(header);

win.open();

尝试 #2 plain jane .xml 和 .tss 样式:

index.js:

$.index.open();

index.xml:

<Alloy>
    <Window class="container">
        <Label id="label">Hello World!!</Label>
        <ImageView id='img1'></ImageView>
    </Window>
</Alloy>

index.tss:

".container": {
    backgroundColor: 'white'
}

"#img1": {
    width: 300,
    image: '/header.png',
    width: 300,
    top: 0,
    left: 0
}

文件位置(我将同一张图片复制到 3 个不同的位置以尝试获取一些东西):


重要,我已经尝试过:

非常简单!

Alloy 示例:

将您的图片放在 app/assets/images 例如 app/assets/images/header.png .

现在您的密码是

   <ImageView id='img1' image='/images/header.png'  ></ImageView>

或在 .tss 文件中

"#img1": {
    width: 300,
    image: '/images/header.png',
    width: 300,
    top: 0,
    left: 0
}

结束!

首先,在 ImageView 属性 中你提到了两次宽度,所以你可以删除一个声明并放置图像的高度,例如 300(你可以放置 Ti.UI.SIZE 以保持纵横比)

其次,将图片分别放在app/asset/android/images/res-<density>里面。将 <density> 替换为例如 mdpi / hdpi / xhdpi。 (你可以把它放在res-hdpi中进行测试)

做一个干净的构建,然后检查它是否得到反映。

放上你的图片: app/assets/images/header.png

然后使用

访问它
<ImageView id='img1' image="/images/header.png"></ImageView>

重要提示:在 运行 应用程序之前,尝试先清理您在资产文件夹中所做的每项更改!