【问题标题】:Cannot resolve symbol @drawable/ic_launcher [duplicate]无法解析符号@drawable/ic_launcher [重复]
【发布时间】:2015-03-24 21:21:12
【问题描述】:

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

Cannot resolve symbol '@drawable/ic_launcher'

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

项目结构:

布局.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>

【问题讨论】:

    标签: android


    【解决方案1】:

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

    @drawable/ic_launcher
    

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

    @mipmap/ic_launcher
    

    mipmaps - 仅用于图标 - mipmap vs drawable folders

    drawables - 用于图标以外的图像

    据此Google blogpost:

    最好将您的应用程序图标放在 mipmap- 文件夹中(而不是 drawable- 文件夹),因为它们使用的分辨率不同于 设备的电流密度。

    【讨论】:

    • 感谢您解释 drawable 和 mipmap 文件夹之间的区别。
    【解决方案2】:

    您的drawable 在mipmap 内,应该用于应用启动器。如果您想将其用作可绘制对象,则应将其复制到 drawable/ 文件夹之一中

    【讨论】:

    • 我现在看到了,肯定是在我更新 Android Studio 时更改的。有什么简单的方法可以将它们复制到我(刚刚创建的)可绘制文件夹中吗? ctrl + c 和 ctrl + v 在 AS 中似乎不起作用。我必须使用文件资源管理器吗?
    • 它适用于 mac。如果你不在windows上,使用shell..这是最快的方法
    • @Marcus, [shift] + [f6] 快速重命名文件夹。 Mipmap 是绘制可绘制对象的新方法。
    • 按照@JaredBurrows 的建议,我最终将其引用为@mipmap/ic_launcher。为您的努力 +1,谢谢。
    • 这不会被认为是错误的,你只会得到不同的行为。基本上最适合的资源将从您的 ImageView 的 mipmap 文件夹中选择,而不是从相应的 drawable 文件夹中选择为您的密度标记的图像。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2019-03-26
    • 2017-04-24
    相关资源
    最近更新 更多