-1

我是 android 开发的新手,我正在尝试按照本书中的说明进行操作。http://amzn.to/4nck80我就是无法让它工作!

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" ></LinearLayout>



    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="@string/hello" />



    <TextView

         android:layout_width="fill_parent"

         android:layout_height="wrap_content"

         android:text="This is my first android application!" />

    <Button

         android:layout_width="fill_parent"

         android:layout_height="wrap_content"

         android:text="And this is a clickable button!" />



</Button>LinearLayout>

我收到错误

文档中根元素之后的标记必须格式正确。

通过第一个 Textview 和警告

在布局文件中发现意外的文本:“LinearLayout>”

经过</Button>LinearLayout>

4

2 回答 2

2

此 XML 文件有几个错误。

首先,您有一个无效的 XML 标记。

改变:

</Button>LinearLayout>

至:

</Button></LinearLayout>

您还需要</LinearLayout>从上面删除关闭,因为您可能并不是要在此处结束根元素。

最后,删除:

</Button>

由于按钮元素以结束/>并因此已经关闭。

最终工作版本

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="This is my first android application!" />

    <Button
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="And this is a clickable button!" />

</LinearLayout>
于 2013-03-27T22:54:06.177 回答
0

中间的linearlayout标签是不必要的。您应该为您创建的每个视图元素创建一个 id。id 允许您调用 mainactivity java 类中的元素。下面是如何制作ID:

<Button
android:id = "@+id/button1"
android:layout_width="wrap_content"
Etc.........
/>

<TextView
android:id = "@+id/mytextview"
Etc......
/>

按照上面的建议修复最后一行的 LinearLayout 标签。

周一Yolo现金赃物

于 2013-03-27T23:37:14.360 回答