Android Studio无法在res / drawable中检测到源文件 Android Studio

问题描述

这是我的代码。我不知道如何发布这张图片

this is my code. i don't know how to post this image

我试图为ImageView添加文件。但这是行不通的。我试图复制路径文件夹,但仍然无法使用。

解决方法

解决方案-第一个问题

资源名称必须以字母(而不是数字)开头。

解决方案-第二个问题

仅使用:

@drawable/039_cloud

代替

@drawable/039_cloud/039_cloud

如此:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/039_cloud" />

Android Studio

Android Studio正在将相同的图像分组,但针对不同的DPI。

选择Android视图时,您将拥有:

enter image description here

但是当您选择Project时,您会看到“真实的”项目结构:

enter image description here

,

复制图像资源并将其直接粘贴到drawable文件夹内。重命名图片,使其不包含数字(例如image_thirty_nine.png)。然后试试这个

 <ImageView
android:id="@+id/image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_thirty_nine" />

如果尝试上述步骤后直到遇到相同的错误,请尝试以编程方式添加图像资源

//ensure you assignn an id to your image
   ImageView imageView = findViewById(R.id.image_id);
    imageView.setImageResource(R.drawable.image_thirty_nine);  

然后运行您的代码以查看其是否有效