我是这个 Android 开发的新手,我发现它的布局真的很混乱。我正在尝试在视图上添加背景图像,并且我尝试使用此示例 添加背景图像以在 xml Android 中形成形状,但它看起来非常糟糕(您知道的位图)
所以我认为向量可能很有趣。唯一的问题是我什至无法使用官方示例。我试过将其设置为背景
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="256dp"
android:width="256dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path android:fillColor="#8fff" android:pathData="M20.5,9.5
c-1.955,0,-3.83,1.268,-4.5,3
c-0.67,-1.732,-2.547,-3,-4.5,-3
C8.957,9.5,7,11.432,7,14
c0,3.53,3.793,6.257,9,11.5
c5.207,-5.242,9,-7.97,9,-11.5
C25,11.432,23.043,9.5,20.5,9.5z" />
It renders in the design view and all, but the attributes viewportWidth
, viewportHeight
, fillColor
and pathData
all show the same warning:
The 'http://schemas.android.com/apk/res/android:viewportWidth' is not declared
如果我检查文件,果然,它不在那里。这是否意味着我必须显式声明所有这些类型?香草示例似乎有点奇怪。
请注意,如果我删除警告前面的“android”,它会删除警告但仍然给我相同的部署错误
Android.Views.InflateException: Binary XML file line #1: Error inflating class <unknown>
原文由 LaughingMan 发布,翻译遵循 CC BY-SA 4.0 许可协议
问题
Intellisense 无法选择我们键入的属性,尽管这些属性存在于 android SDK 中并且显示此属性未声明。
解决方案
我昨天在 Visual Studio 2015 中遇到了这个问题并开始搜索,最终我发现这两个文件在 Visual Studio 的 XML 模式文件夹中丢失,所以下载下面给出的这些文件链接,
只需手动下载文件并将其移动到 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Xml\Schemas 或只是在 Visual Studio 中添加这些模式。这个错误就会消失,我用这个程序解决了这个问题。