我正在从一本书中构建我的第一个Android程序.它一直在崩溃XML文件.我从书中下载了xml代码,使用它并且运行正常!
当我看着它们时,它们对我来说都是一样的!我是否遗漏了一些关于XML的内容 - 是否存在有趣的空白空间问题,大写字母,特殊字符或者我的XML中只有一个奇怪的gremlin!
它现在正在运作,但我想知道原因.
这有效!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
这不起作用:崩溃:java.lang.runtime.exception.二进制xml文件lin#1:您必须提供layout_width属性.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android.layout_width="fill_parent"
android.layout_height="fill_parent"
android:padding="10dip">
<TextView
android:id="@+id/about_content"
android.width ="wrap_content"
android.height ="wrap_content"
android:text="@string/about_text"/>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
在不起作用的XML中,您.在属性名称中有句点():
android.layout_width
Run Code Online (Sandbox Code Playgroud)
和
android.layout_height
Run Code Online (Sandbox Code Playgroud)
需要使用冒号(:)代替:
android:layout_width
Run Code Online (Sandbox Code Playgroud)
和
android:layout_height
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
178 次 |
| 最近记录: |