【问题标题】:What is a Multiple Root Tag Problem in Android Studio什么是 Android Studio 中的多根标签问题
【发布时间】:2020-07-17 08:22:05
【问题描述】:

我刚在android studio学习应用程序开发,我没有很好的java背景,在学习布局时遇到了一个错误,提示多根标签错误,这里是ly代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Hello Carl!"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintLeft_toLeftOf="parent"
     app:layout_constraintRight_toRightOf="parent"
     app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width ="fill_parent"
 android:layout_height ="fill_parent"
 android:orientation= "vertical">
 <Button android:id ="@+id/btnStart"
     android:layout_width ="270dp"
     android:layout_height= "wrap_content"
     android:text ="@+string/Start" />
</LinearLayout>

我该如何解决这个问题,请说明我是否应该一次只使用一种布局?

【问题讨论】:

    标签: android xml android-studio layout


    【解决方案1】:

    您的 XML 布局文件中只能有一个根标签。

    例子:

    <androidx.constraintlayout.widget.ConstraintLayout
    ...your main content...
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    将您的LinearLayout 移到有...your main content... 的地方

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 2021-07-18
      • 1970-01-01
      相关资源
      最近更新 更多