2014-06-18 43 views
8

我是编辑我fragment_main.xml Android Studio中,和我收到此错误:多根标签

多个根标签

这里有问题的代码块:

<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和以前按钮

+6

将EditText和Button放入线性布局中。 –

+0

不,我只是把它放在线性布局谢谢! – rakeshdas

回答

10

由于Android的每一个XML文件中必须有只有一个根布局。只需在LinearLayout中添加EditText和Button即可。正确的代码如下所示

<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>