1

我在 Eclipse Kepler 中有一个 android 应用程序,它有一个名为 TheBackground.png 的背景图像。

我将 TheBackground.png 添加到 res/drawable-mdpi,我的 activity_main.xml 以:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/TheBackground.png"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

但 Eclipse 在 android:background 行抛出此错误:

找不到与给定名称匹配的资源(在“背景”,值为“@drawable/TheBackground.png”)

我尝试将 TheBackground.png 添加到所有 res/drawable-*dpi 文件夹,并创建一个 res/drawable 文件夹并将其添加到那里,但它返回相同的错误。

请注意,文件名确实指向有效的 PNG 图像。

我错过了什么吗?

4

5 回答 5

4

重命名您的 png 图像文件,所有字符必须为小写。

 android:background="@drawable/the_background.png"

资源编译器在处理之前将目录名称转换为小写,以避免在不区分大小写的文件系统上出现问题。名称中的任何大写仅是为了提高可读性。

于 2013-07-27T19:50:00.677 回答
2

设置drawable时你只是不需要“.png”。并使用小写。

android:background="@drawable/the_background"
于 2013-07-27T20:19:13.307 回答
1

将 png 文件的名称更改为小写

于 2013-07-27T19:55:10.860 回答
0

将您的 .png 文件重命名为小写。

通过右键单击项目然后刷新,或单击项目后按 F5 来刷新您的 Eclipse 项目。

把它清理干净Project->Clean,然后你就可以走了!

于 2013-07-27T20:22:08.867 回答
0

将其设为小写是解决方案的一半;显然,它不喜欢添加到其中的“.png”。当我将其更改为“@drawable/the_background”时,它编译成功。

于 2013-07-27T20:22:44.240 回答