我在文件夹drawable-hdpi
,-ldpi
,-mdpi
中复制了两张图片,并将该图片引用到了一个按钮。
我的控制台出现以下错误:“找不到与给定名称相匹配的资源”。
我做错了什么?“你好”是我从资源文件夹中引用的图像的名称。即使在将图像引用到按钮之前,我在资源文件夹中添加图像时出现错误。
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text=""
android:background="@drawable/hello"
android:layout_x="190dp"
android:layout_y="220dip">
</Button>
答案 0 :(得分:1)
您是否尝试按ID
访问图片R.drawable.your_image
可以从Assets文件夹中按名称访问资源。
答案 1 :(得分:1)
在XML中,您还需要添加引用的类型:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image" />
答案 2 :(得分:1)
尝试这样做。
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image"
android:background="@null"
/>
如果问题仍然存在,请尝试清理项目并运行它。
答案 3 :(得分:0)
R.drawable.nostatusindicator
其中nostatusindicator是-hdpi
,-mdpi
,-ldpi
中可绘制目录中的文件,请检查名称中是否应该包含大写字母并且在这些文件的名称中也没有超出字符,但下划线。
更新:看了你的代码后看起来不错。干净再次构建它。并假设您的文件位于drawable-hdpi
,-ldpi
,-mdpi
....的至少一个文件夹中,或者重新启动eclipse应用程序。
清理并运行:当在eclipse中打开项目菜单并按下清洁然后运行(构建在项目中自动完成构建时自动完成)项目,就像通常对任何要测试的应用程序所做的那样你的模拟器。这会清除构建文件,这些文件有时可能无法针对像图像添加等类似的小变化进行更新...当您尝试将图像添加到其中时,您甚至会说您有冲突....
答案 4 :(得分:0)
您应该将以下代码添加到MainActivity类中,并将图像复制到dhpi文件夹,分别使用ic_launcher,ic_launcher2,ic_launcher3和ic_1作为图像名称,您还可以更改大小,宽度和高度。
int array_image[] = {
R.drawable.ic_launcher,
R.drawable.ic_launcher2,
R.drawable.ic_launcher3,
R.drawable.ic_1
}