AndroidManifest:忽略未知的“形状” XML元素

发布于 2024-12-20 03:04:30 字数 1108 浏览 4 评论 0原文

由于某种原因,我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反话 2024-12-27 03:04:30

您可能会收到错误,因为您将此 XML 放在了错误的位置。上面的 XML 应位于 res/drawable 目录中。您确实不应该在布局中绘制正方形。在视图中绘制一个正方形并将其添加到布局中。或者使用图像并通过 ImageView 将其添加到视图中。布局是视图的聚合。如果您确实想在布局(ViewGroup)中绘制一个正方形,您可以扩展它并在 onDraw() 方法中绘制它。但这可能会比需要的更复杂。查看有关布局的 Android 文档:http://developer.android。 com/guide/topics/ui/index.html

You'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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文