當嘗試關閉主LinearLayout中的嵌套LinearLayout時,它需要關閉屬于主LinearLayout,而第二個LinearLayout(TextView,TextView和Button)之后的其余代碼不起作用并出現錯誤Multiple root tags and Cannot解決類(TextView、TextView 和 Button),有人可以幫幫我嗎?
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="quantity"
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_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="decrement"
android:text="-"
android:textSize="24sp" />
<TextView
android:id="@ id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="0"
android:textColor="@android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="increment"
android:text=" "
android:textSize="24sp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="price"
android:textAllCaps="true" />
<TextView
android:id="@ id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="$0"
android:textColor="@android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="submitOrder"
android:text="order" />
</LinearLayout>
uj5u.com熱心網友回復:
那是因為你已經自我關閉了第二個 LinearLayout,然后在下面你已經把它變成了容器,所以下面的代碼不包含在線性塊代碼中!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
你不應該像這樣關閉它應該是這樣的
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
這是完整的代碼
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="quantity"
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_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="decrement"
android:text="-"
android:textSize="24sp" />
<TextView
android:id="@ id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="0"
android:textColor="@android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="increment"
android:text=" "
android:textSize="24sp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="price"
android:textAllCaps="true" />
<TextView
android:id="@ id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="$0"
android:textColor="@android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:backgroundTint="@android:color/holo_green_light"
android:onClick="submitOrder"
android:text="order" />
</LinearLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/474137.html
上一篇:清單檔案中未指定包
