Android Studio 中的多个根标签 [英] Multiple root tags in Android Studio
本文介绍了Android Studio 中的多个根标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 Android Studio 中编辑我的 fragment_main.xml,但出现此错误:
I am edit my fragment_main.xml in Android Studio, and I am getting this error:
多个根标签
这里有问题的代码块是:
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 之前和 Button
I am getting the errors in the brackets before EditText and before Button
推荐答案
由于在 Android 中每个 xml 文件必须只有一个根布局. 只需在 LinearLayout 中添加 EditText 和 Button 即可.正确的代码如下所示
Since in Android every xml file there must be only one root 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>
这篇关于Android Studio 中的多个根标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文