该属性未在基本 xml 属性上声明 (Android)

新手上路,请多包涵

我是这个 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 许可协议

阅读 294
2 个回答

问题

Intellisense 无法选择我们键入的属性,尽管这些属性存在于 android SDK 中并且显示此属性未声明。

解决方案

我昨天在 Visual Studio 2015 中遇到了这个问题并开始搜索,最终我发现这两个文件在 Visual Studio 的 XML 模式文件夹中丢失,所以下载下面给出的这些文件链接,

  1. https://github.com/atsushieno/monodroid-schema-gen/blob/master/android-layout-xml.xsd
  2. https://github.com/atsushieno/monodroid-schema-gen/blob/master/schemas.android.com.apk.res.android.xsd

只需手动下载文件并将其移动到 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Xml\Schemas 或只是在 Visual Studio 中添加这些模式。这个错误就会消失,我用这个程序解决了这个问题。

原文由 Usman 发布,翻译遵循 CC BY-SA 3.0 许可协议

据我所知,那些属性(你在上面指出的) 没有在 jdk_1.7 中定义

请改用 jdk_1.8。

您可以通过以下方式配置 JDK 的路径:

Microsoft Visual Studio 2015 -> 工具 -> 选项 -> Xamarin -> Android 设置 -> JDK 位置 [更改]

评论

如果您使用的是 Microsoft Visual Studio 2015 Update 3 或早期版本之一,我向您保证警告不会消失……这已经是 Intellisense 的问题(不是 JDK 的问题)。它必须在未来的版本中修复。

截屏

原文由 AlexMelw 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题