英文:
Vector drawables not loading in xml ResourceNotFoundException
问题
我在加载矢量文件时在我的闪屏背景 XML 文件中遇到了问题。矢量文件已经成功加载,因为我可以在 Android Studio 中打开矢量文件,并且在 XML 文件的一侧获得矢量图形的小图标。然而,XML 文件的设计视图显示矢量文件存在错误,并且在尝试运行我的应用程序时出现 ResourceNotFoundException 错误。
以下是代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_loading_screen_logo"/>
</item>
</layer-list>
[闪屏背景.xml][1]
[1]: https://i.stack.imgur.com/nbxvJ.jpg
我的 Gradle 版本是 `classpath 'com.android.tools.build:gradle:4.0.1'`
我在 Gradle 应用程序文件中添加了以下行 `vectorDrawables.useSupportLibrary = true`
似乎我使用的任何矢量文件都有这个错误,因此可能缺少某种设置。
请以任何方式协助,谢谢!
英文:
I am having trouble with loading vector files in my splash background xml file. The vector has been loaded successfully because I can open the vector file in android studio and I get a small graphic of the vector on the side of the xml file. However, the design view of the xml file shows an error for the vector file, and I get a ResourceNotFoundException when trying to run my app.
Code below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_loading_screen_logo"/>
</item>
</layer-list>
My grade version is classpath 'com.android.tools.build:gradle:4.0.1'
and I have included the following line in my grade app file vectorDrawables.useSupportLibrary = true
It seems that any vector file that I use has this error, so there is some setting of some sort that is missing.
Please assist in anyway.
Thanks,
答案1
得分: 0
问题是将xml可绘制对象包装在一个<bitmap/>
中。
尝试这样做:
将以下部分替换为:
<item android:gravity="center"
android:drawable="@drawable/ic_loading_screen_logo"/>
英文:
The problem is wrapping the xml drawable in a <bitmap/>
Try this:
Replace
<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_loading_screen_logo"/>
</item>
With:
<item android:gravity="center"
android:drawable="@drawable/ic_loading_screen_logo"/>
答案2
得分: 0
Sure, here's the translation:
- 将
<bitmap
替换为<item
- 确保你的矢量图像位于
drawable
文件夹中,而不是drawable-24
。 - 检查矢量图像的
path
,也许它太长了。
英文:
- replace
<bitmap
to<item
- make sure that your vector is in drawable folder not in drawable-24.
- check vectory
path
may be its too long.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论