简体   繁体   English

Android Studio 无法为 ImageView 找到可绘制资源

[英]Android Studio not able to find drawable resource for ImageView

I am using Android Studio 3.0.1, I have a simple xml file with root ConstraintLayout , so when I do preview and drag and drop an ImageView from the Preview Palette , it is not able to find the new added png file, which I have copy/paste directly in the project directory, not in Android Studio.我使用的是 Android Studio 3.0.1,我有一个带有根ConstraintLayout的简单 xml 文件,所以当我从Preview Palette进行预览和drag and drop ImageView ,它无法找到新添加的 png 文件,我有直接在项目目录中复制/粘贴,而不是在Android Studio.

在此处输入图片说明

I have tried clean, rebuild but it is still not able to find the image.我尝试过清理,重建,但仍然无法找到图像。

I know that it will work if I restart it but I think that it is not a good idea to restart each and every time I add a new png file.我知道如果我restart它会起作用,但我认为每次添加新的 png 文件时都restart不是一个好主意。

Is this a bug in Android Studio ?这是Android Studio的错误吗?

Have anyone else experienced this?有没有其他人经历过这种情况?

File - Sync with file system may help.文件 - 与文件系统同步可能会有所帮助。 Looking at your file names above, they should be ok as I hit the same problem due to using an upper case char at the start of the filename.查看上面的文件名,它们应该没问题,因为我遇到了同样的问题,因为在文件名的开头使用了大写字符。

By building the project, I was alerted to this by the following error: "H is not a valid file-based resource name character: File-based resource names must contain only lowercase az, 0-9, or underscore"通过构建项目,我收到以下错误警告:“H 不是基于文件的有效资源名称字符:基于文件的资源名称必须仅包含小写字母 az、0-9 或下划线”

Drawable folder host images, so try putting your images in this folder when using imageView. Drawable 文件夹托管图像,因此在使用 imageView 时尝试将图像放在此文件夹中。

A workaround for images organization (since the project's folder structure should prevail flat) is using underscore rather that forward dash.图像组织的一种解决方法(因为项目的文件夹结构应该是扁平的)是使用下划线而不是向前破折号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM