【问题标题】:Eclipse add tabhost to project errorEclipse将tabhost添加到项目错误
【发布时间】:2011-10-12 05:23:12
【问题描述】:

当我尝试使用添加 TabHost 时

RightClick > New > Android XML > Select Root Element :TabHost

它表明 tabhost 需要一个 tabwidget 和框架布局。

其实tabhost是root。我怎样才能有一个 tabwidgetframe layout 之前?

这是日食的错还是我的错?

【问题讨论】:

    标签: android eclipse android-tabhost


    【解决方案1】:

    在使用 Eclipse 3.7.1 安装 ADK 2.3.3 更新 2 后,此功能应如您所描述的那样工作。

    【讨论】:

      【解决方案2】:

      如您在 Eclipse 3.7.1 中所述,我能够使用根 TabHost 创建布局,没有任何错误。我相信作为解决方法,您可以使用 LinearLayout 作为根创建布局,然后将 TabHost 放入其中或使用 TabHost 切换 LinearLayout。

      编辑:

      <?xml version="1.0" encoding="utf-8"?>
      <TabHost
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
         <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
         </TabWidget>
         <FrameLayout
            android:id="@android:id/tabcontent" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
         </FrameLayout>  
      </TabHost>
      

      【讨论】:

      • 我尝试将 LinearLayout 更改为 tabhost 它再次显示如下 :: TabHost 需要一个 ID 为“android:id/tabs”的 TabWidget。异常详细信息记录在 Window > Show View > Error Log :: 但是在 linearlayout 下添加 tabHost 工作正常。谢谢
      • 很高兴工作。你试过直接将 TabWidget 和 FrameLayout 添加到 xml 文件吗?
      • 没有,当我在linearlayout下添加tabhost时,它们都自动添加了
      • 你需要把tabhost的id放在上面的布局android:id="@android:id/tabhost"
      • 切换我的布局也不起作用,但是当我从带有 tabhost 的 xml 中键入或粘贴整个内容时,它可以工作..
      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 2015-01-29
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 2011-06-06
      相关资源
      最近更新 更多