在Android的工作室多根标签工作室、标签、Android

2023-09-07 22:11:47 作者:冷言冷语冷回忆

我是编辑我fragment_main.xml在Android的工作室,和我收到此错误:

I am edit my fragment_main.xml in Android Studio, and I am getting this error:

多个根标签的

Multiple Root Tags

在这里讨论的code块是:

The code block in question here is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>
<EditText   <!--Error here in the bracket-->
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button    <!--Error here in the bracket-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"/>

我收到错误的括号之前的的的EditText 的和之前的的按钮的

I am getting the errors in the brackets before EditText and before Button

推荐答案

由于Android的每一个XML文件只能有一个父布局。只需添加的EditText和Button了的LinearLayout内。右code如下所示

Since in Android every xml file there must be only one parent layout. Just add the EditText and Button inside the LinearLayout. Right code is shown below

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText  
android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />

<Button    
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"/>

</LinearLayout>
 
精彩推荐