【问题标题】:Multiple root tags in Android Studio [duplicate]Android Studio中的多个根标签[重复]
【发布时间】:2014-06-18 00:58:19
【问题描述】:

我在 Android Studio 中编辑我的 fragment_main.xml,我收到了这个错误:

多个根标签

这里有问题的代码块是:

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

我在 EditTextButton

之前的括号中出现错误

【问题讨论】:

  • 将 EditText 和 Button 放入线性布局中。
  • 不,我只需要把它放在线性布局中谢谢!

标签: java android android-layout android-fragments


【解决方案1】:

由于在 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>

【讨论】:

    猜你喜欢
    • 2020-07-17
    • 2015-07-02
    • 2022-12-13
    • 2018-12-25
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 2021-11-30
    • 2019-06-10
    相关资源
    最近更新 更多