AndroidManifest:忽略未知的“形状” XML元素
由于某种原因,我的 Android 项目编译正确,在手机和模拟器上运行良好,甚至包含多个带有 LinearLayouts、TextView、按钮、图像、甚至自定义 View 组件的 XML 布局文件,但当涉及到形状时,它根本不能找到他们。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:radius="30dp"/>
</shape>
以及我在 eclipse 中的图形布局中遇到的错误:
com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- shape (Fix Build Path, Edit XML)
- solid (Fix Build Path, Edit XML)
我的目标是 Android 2.2 Froyo Google API。
建议?
For some reason my Android project compiles properly, runs fine on both phones and emulators, and even includes multiple XML layout files with LinearLayouts, TextViews, Buttons, Images, and even custom View components, but when it comes to shapes it simply can't find them.
Heres my code:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:radius="30dp"/>
</shape>
And the error I get in the graphical layout in eclipse:
com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- shape (Fix Build Path, Edit XML)
- solid (Fix Build Path, Edit XML)
I'm targeting Android 2.2 Froyo Google APIs.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您可能会收到错误,因为您将此 XML 放在了错误的位置。上面的 XML 应位于
res/drawable
目录中。您确实不应该在布局中绘制正方形。在视图中绘制一个正方形并将其添加到布局中。或者使用图像并通过 ImageView 将其添加到视图中。布局是视图的聚合。如果您确实想在布局(ViewGroup)中绘制一个正方形,您可以扩展它并在 onDraw() 方法中绘制它。但这可能会比需要的更复杂。查看有关布局的 Android 文档:http://developer.android。 com/guide/topics/ui/index.htmlYou're probably getting the error because you're putting this XML in the wrong place. The XML above should go in the
res/drawable
directory. You really should not draw a square in the Layout. Draw a Square in a View and add it to the Layout. Or use an image and add it to a View via an ImageView. A Layout is an aggregation of Views. If you really want to draw a Square in a Layout (ViewGroup) you can extend one and draw it in the onDraw() method. But that'll probably be more complicated than needed. Have a look at the the Android Docs on Layouts: http://developer.android.com/guide/topics/ui/index.html