Android XML 有空体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23770123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML has empty body?
提问by juliet
I am new to working with XML and am editing a layout in my Android app and it is giving me the error "XML has empty body" is anyone able to tell me what I have done wrong? This is my code:
我是 XML 的新手,正在我的 Android 应用程序中编辑布局,它给了我错误“XML 有空主体”有谁能告诉我我做错了什么?这是我的代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/orange"></solid>
<stroke
android:width="2dp"
android:color="@color/orange"></stroke>
<padding
android:bottom="10dp"
android:left="15dp"
android:right="15dp"
android:top="15dp"></padding>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:radius="1dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
Thanks
谢谢
Edit: had to add spaces to make first 2 lines appear...
编辑:必须添加空格才能显示前 2 行...
回答by juliet
It appears to have worked by getting rid of the closing tags and replacing them with the self closing tags:
它似乎通过摆脱关闭标签并用自关闭标签替换它们而起作用:
<solid android:color="@color/orange" />
<stroke
android:width="2dp"
android:color="@color/orange" />
<padding
android:bottom="10dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:radius="1dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
回答by influx
Replace the tag
更换标签
<solid android:color="@color/orange"></solid>
instead of
代替
<solid android:color="@color/orange"/>
//like wise all tags
//像所有标签一样明智
回答by Red M
Replacing < include layout = "@layout/layout> < /include>with: < include layout = "@layout/layout />worked fine for me.
将 < include layout = "@layout/layout> </include>替换为: < include layout = "@layout/layout />对我来说效果很好。
回答by panini
all Android XML layout files need to start with the line:
所有 Android XML 布局文件都需要以以下行开头:
<?xml version="1.0" encoding="utf-8"?>
so your file should look like:
所以你的文件应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="schemas.android.com/apk/res/android"
android:shape="rectangle>
<solid android:color="@color/orange"></solid>
<stroke
android:width="2dp"
android:color="@color/orange"></stroke>
<padding
android:bottom="10dp"
android:left="15dp"
android:right="15dp"
android:top="15dp"></padding>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:radius="1dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
回答by Brainnovo
Just place the closing tag on a new line, for example replace:
只需将结束标记放在新行上,例如替换:
<solid android:color="@android:color/white"></solid>
with:
和:
<solid android:color="@android:color/white">
</solid>
回答by learn native
the second must be written two lines down.just put the cursor before the second and the problem is solved.
第二个必须写两行。只需将光标放在第二个之前,问题就解决了。