无法解析符号@ drawable/ic_launcher [英] Cannot resolve symbol @drawable/ic_launcher
问题描述
我的布局中有一个ImageView
,请参见下面的代码.当我尝试将src
属性设置为启动器图标时,出现以下错误:
I have an ImageView
in my layout, see below code. When I'm trying to set the src
attribute to be my launcher icon, I get the following error:
Cannot resolve symbol '@drawable/ic_launcher'
ic_launcer.png已添加到我的drawables文件夹中,请参见下图.为什么我不能在ImageView
中引用我的图像?
ic_launcer.png is added to my drawables folder, see below image. Why can I not reference my image in my ImageView
?
项目结构:
Layout.xml:
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>
推荐答案
更改(您没有可绘制的文件夹):
@drawable/ic_launcher
收件人(您正在使用mipmap文件夹):
@mipmap/ic_launcher
mipmaps -仅用于图标- mipmap与可绘制文件夹
可绘制对象-用于图标以外的图像
drawables - used for images other than icons
据此 Google网志:
最佳做法是将您的应用程序图标放置在mipmap-文件夹中(而不是 drawable-文件夹),因为它们的使用分辨率与 设备的电流密度.
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.
这篇关于无法解析符号@ drawable/ic_launcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!