android - 多个根标签错误

标签 android android-studio compiler-errors

我是 Android 开发和编程的新手。我尝试编写一些布局代码,但我得到了

Multiple root tags error

谁能帮帮我?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="This is my first android app!" />

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button!" />

</LinearLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello!" />

    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="This is my first android app!" />

    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button!" />

</LinearLayout>

我能够以这种方式修复它,但如果在第一个 TextView 文本中我输入“@string/Hello”,它就不起作用,有人能告诉我为什么吗?

最佳答案

试试这个:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is my first android app!" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button!" />

    </LinearLayout>

关于android - 多个根标签错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29457132/

相关文章:

java - android studio 启动权限被拒绝,怎么办?

java - ksoap2 android 发送数据

android - 单击按钮时的条件

java - 在 IntelliJ IDEA : "No MessageCollector" 中编译时出错

objective-c - 错误: incompatible types in assignment

android - 从 parcelable 对象中读取字符串返回 null

android - 使用 Mockito 模拟构建版本

java - 如何修复我的 Android Studio IDE? (错误 23,24;错误 26,13,缺少类和渲染问题)

android - Bytedeco的Tesseract库是通过gradle依赖添加的,但是没有找到

java - GWT 2.8.2编译器异常