Eclipse不会在任何可绘制文件夹中识别PNG

时间:2013-07-27 19:43:10

标签: android eclipse drawable

我在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:后台行抛出此错误:

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

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

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

我错过了什么吗?

5 个答案:

答案 0 :(得分:4)

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

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

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

答案 1 :(得分:2)

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

android:background="@drawable/the_background"

答案 2 :(得分:1)

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

答案 3 :(得分:0)

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

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

Project->Clean清除它,然后你应该好好去!

答案 4 :(得分:0)

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

相关问题