简体   繁体   English

xml ResourceNotFoundException 中未加载矢量可绘制对象

[英]Vector drawables not loading in xml ResourceNotFoundException

I am having trouble with loading vector files in my splash background xml file.我在我的飞溅背景 xml 文件中加载矢量文件时遇到问题。 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.向量已成功加载,因为我可以在 android studio 中打开向量文件,并在 xml 文件的一侧得到一个向量的小图形。 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.但是,xml 文件的设计视图显示矢量文件错误,并且在尝试运行我的应用程序时出现 ResourceNotFoundException。

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>

splash background.xml飞溅背景.xml

My grade version is classpath 'com.android.tools.build:gradle:4.0.1'我的成绩版本是classpath 'com.android.tools.build:gradle:4.0.1'

and I have included the following line in my grade app file vectorDrawables.useSupportLibrary = true我在我的成绩应用程序文件中包含了以下行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,谢谢,

The problem is wrapping the xml drawable in a <bitmap/>问题是将 xml drawable 包装在<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"/>

  1. replace <bitmap to <item<bitmap替换为<item
  2. make sure that your vector is in drawable folder not in drawable-24.确保您的矢量位于 drawable 文件夹中,而不是 drawable-24 中。
  3. check vectory path may be its too long.检查矢量path可能太长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM