Подтвердить что ты не робот

Несколько корневых тегов в Android Studio

Я редактирую свой файл 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 и до Кнопка

4b9b3361

Ответ 1

Поскольку в Android каждый XML файл должен иметь только один корневой макет. Просто добавьте EditText и Button внутри LinearLayout. Правильный код показан ниже

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