【问题标题】:No resource found that matches the given name (at 'src' with value '@android:drawable/logo.png找不到与给定名称匹配的资源(在 'src' 处,值为 '@android:drawable/logo.png
【发布时间】:2018-06-23 20:59:00
【问题描述】:

首先我是一个初学者,自学编程。 我正在使用 Visual Studio Xamarin 创建一个 android 应用程序。我正在尝试将名为 logo.png 的图像分配给 imageview。我在资源文件下没有可绘制文件,因此我添加了一个文件夹,将其命名为“可绘制”。然后我粘贴了 logo.png。 imageview的xml代码:

<ImageView
    android:src="@android:drawable/logo.png"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/imageView1" />

我没有修改任何 java/C# 文件。 我在资源下的一些不寻常的文件夹包括 mipmap-anydpi、mipmap-hdpi、mipmap-mdpi、mipmap-xhdpi、mipmap-xxhdpi、mipmap-xxxhdpi。我尝试在所有这些文件夹上使用 logo.png 并尝试使用相同的 xml 代码进行构建,但没有改进。 (顺便说一句,我几乎不知道任何 xml)。在这种情况下,它表示activity_main.axml,与它在名为activity_main.axml的Android Studio上的情况相比。这与问题有什么关系吗?顺便说一句,我正在关注本教程:https://youtu.be/WBTZ7TSan_E

【问题讨论】:

  • @mipmap/logo替换@android:drawable/logo.png

标签: c# android xml


【解决方案1】:

如果你把logo.png:

src/drawable/ 上使用 @drawable/logo.png

如果在 src/mipmap/ 上使用 @mipmap/logo.png

为什么不@android:

这个路径指向android资源,是默认文件,属于Android SDK

【讨论】:

  • 非常感谢。幸运的是,这两个代码都运行良好。会不会影响速度什么的。可能是什么原因导致它在 @android:drawable/logo 时不起作用而在 @drawable/logo 时起作用。
【解决方案2】:

Android 操作系统有自己的资源,如颜色变量、默认尺寸、主题等。

如果您使用手机中存在的一些内部可绘制资源,那么您使用:

android:src="@android:drawable/..."

如果您使用在您的应用中添加的资源,在您的文件夹 drawable 中,则使用:

android:src="@drawable/..."

记住这一点很重要,因为您会经常遇到这种情况。

【讨论】:

  • IDK 如果它的内部或我在应用程序中添加的资源。但它对后一种有效。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多