我是 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/