意外的标记错误?

问题描述 投票:0回答:1

我正在为一个类编码,并在垂直线性布局中嵌套了一个水平线性布局。

现在android studio无法识别收尾标签,导致意外的token错误,而且我在嵌套布局之后的每个元素都收到一个根标签错误。

我对照老师的代码检查了一下,似乎完全一样。

我肯定是我漏掉了一些很简单的东西。有什么好办法吗?

我的代码。

 `<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:text="Quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="true"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"/>

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginTop="16dp"
            android:onClick="decrement"
            android:text="-"/>

        <TextView
            android:text="2"
            android:textColor="@android:color/black"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginRight="8dp"
            android:layout_marginLeft="8dp"
            android:textSize="16sp" />

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:onClick="increment"
            android:text="+"/>

    </LinearLayout>

    <TextView        <---getting multiple root tag error
        android:text="Price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="true"
        android:layout_marginTop="16dp"/>

    <TextView        <---getting multiple root tag error
        android:text="$10"
        android:textColor="@android:color/black"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="16sp"
        android:layout_marginTop="16dp"/>

    <Button     <---getting multiple root tag error
        android:layout_marginTop= "16dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ORDER"
        android:onClick="submitOrder" />

</LinearLayout>   <---getting unexpected token error`
android
1个回答
3
投票

错误在这里

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"/> <-- this is the error

你应该用

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
© www.soinside.com 2019 - 2024. All rights reserved.