【问题标题】:Error parsing XML: junk after document element, an error in tabhost coding解析 XML 时出错:文档元素后出现垃圾,tabhost 编码出错
【发布时间】:2015-09-08 08:03:11
【问题描述】:

我正在尝试构建 tabhost 编码,但我被困在 .xml 部分。

以下是activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" />

<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:orientation="horizontal" />
<FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>

有人知道这个版本的问题吗?

消息 “错误:(8) 解析 XML 时出错:文档元素后出现垃圾” 出现在 第 7 行。 希望有人知道这个问题并可以帮助我,非常感谢...!!

【问题讨论】:

  • 在 Viewpager 上方设置一个根布局,如相对或线性
  • 您似乎有两个根元素 - ViewPager 和 FragmentTabHost。那是无效的。你的意思是FragmentTabHost 元素在inside ViewPager 元素吗?
  • 我明白了,谢谢。我意识到最后没有包含viewpager root

标签: java android xml android-layout


【解决方案1】:

问题是多个根标签。(一个.xml中不能有两个根标签)

试试这个:

  <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

<android.support.v4.app.FragmentTabHost
      android:id="@android:id/tabhost"
      android:layout_width="match_parent"
      android:layout_height="match_parent" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</android.support.v4.view.ViewPager>

【讨论】:

  • 感谢大佬的帮助,成功了!我刚刚知道有多个根
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-24
  • 2013-01-22
  • 2015-01-29
相关资源
最近更新 更多