【问题标题】:Wasn't able to add resource files to titanium android app无法将资源文件添加到钛 android 应用程序
【发布时间】:2017-01-27 14:01:53
【问题描述】:

我正在使用钛构建一个android应用程序,我需要将一些资源文件(通常添加在android eclipse项目的project/res文件夹中的图像和其他类型)添加到钛应用程序。

所以我尝试将几个图像 - clip_first.png、clip_second.png 复制到[Titanium app folder]/Resources/android/images。但是当它被编译时,资源文件被复制到正确的路径,但名称已经足够了。

我附上了项目的屏幕截图

有没有什么方法可以在没有足够的情况下添加它们?自从我看到default.png也改名为background.png之后,命名规则是什么?

提前致谢。

【问题讨论】:

    标签: android titanium titanium-mobile appcelerator-titanium


    【解决方案1】:

    你应该把你的资源放在文件夹app/assets/android/images/res-{density}/

    例子:

    app/assets/android/images/res-xhdpi/my_image.png
    

    然后您可以将其作为背景图像分配给任何视图:

    myView.backgroundImage = "/images/my_image.png";
    

    不要忘记路径上的领先后倾。

    或使用 tss :

    "#myView" : {
        backgroundImage : "/images/my_image.png";
    }
    

    或将其与图像视图一起使用:

    myImageView.image = "/images/my_image.png";
    

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回答,带有 xml 扩展名的可绘制对象呢?还有像 strings.xml 和原始资源这样的值呢?
    • 当我将文件放入路径时,我得到了一些奇怪的信息,看起来像是文件的哈希值。
    • 我不确定在 imageView 中使用 xml drawables(如选择器),但我可以说的是您可以直接在任何视图上使用 backgroundImage、selectedBackgroundImage 等属性。对于 Strings xml,您必须使用 i18 文件夹,我认为您应该真正阅读文档:docs.appcelerator.com/platform/latest/#!/guide/…
    猜你喜欢
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    相关资源
    最近更新 更多