无法解析符号@ drawable/ic_launcher

Mar*_*cus 18 android

我的ImageView布局中有一个,见下面的代码.当我尝试将该src属性设置为我的启动器图标时,我收到以下错误:

Cannot resolve symbol '@drawable/ic_launcher'
Run Code Online (Sandbox Code Playgroud)

ic_launcer.png被添加到我的drawables文件夹中,见下图.为什么我不能在我的图像中引用我的图像ImageView

项目结构:

项目结构

Layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_weight="1"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Jar*_*ows 39

更改(您没有可绘制的文件夹):

@drawable/ic_launcher
Run Code Online (Sandbox Code Playgroud)

要(您正在使用mipmap文件夹):

@mipmap/ic_launcher
Run Code Online (Sandbox Code Playgroud)

的贴图 -仅用于图标- 纹理贴图VS绘制文件夹

drawables - 用于图标以外的图像

根据谷歌的这篇博文:

最好将应用程序图标放在mipmap文件夹(而不是drawable文件夹)中,因为它们的分辨率与设备的当前密度不同.

  • 感谢您解释“drawable”和“mipmap”文件夹之间的区别。 (2认同)